numpy.matlib.identity()方法

此函数用于返回给定大小的单位矩阵。一个单位矩阵是对角元素初始化为1, 所有其他元素初始化为零的矩阵。

句法

numpy.matlib.ones(size, dtype)

参数

它接受以下参数。

  1. 形状:它是所得身份矩阵中的行数和列数。
  2. dtype:它是单位矩阵的数据类型。

返回

它返回指定大小和指定数据类型的身份矩阵。

例子

import numpy as np  
  
import numpy.matlib  
  
print(numpy.matlib.identity(4))

输出

[[1. 0. 0. 0.]
 [0. 1. 0. 0.]
 [0. 0. 1. 0.]
 [0. 0. 0. 1.]]

示例:具有整数值的单位矩阵

import numpy as np  
  
import numpy.matlib  
  
print(numpy.matlib.identity(4, int))

输出

[[1 0 0 0]
 [0 1 0 0]
 [0 0 1 0]
 [0 0 0 1]]

来源:

https://www.srcmini02.com/30836.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_35704.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?