此函数返回一个矩阵, 该矩阵的对角元素初始化为1, 在其他位置初始化为零。
句法
numpy.matlib.eye(n, m, k, dtype)
参数
它接受以下参数。
- n:代表结果矩阵中的行数。
- m:表示结果矩阵中的数字列。
- k:它是对角线的索引。
- dtype:是输出的数据类型。
返回
返回具有未初始化条目的矩阵。
例子
import numpy as np
import numpy.matlib
print(numpy.matlib.eye(n=3, m=3, k=0, dtype=int))
输出
[[1 0 0]
[0 1 0]
[0 0 1]]
示例:初始化浮点值
import numpy as np
import numpy.matlib
print(numpy.matlib.eye(n=3, m=3, k=0, dtype=float))
输出
[[1. 0. 0.]
[0. 1. 0.]
[0. 0. 1.]]
来源:
https://www.srcmini02.com/30834.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_35702.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57