努比。Python中的矩阵()

此类从数据字符串或类似数组的对象返回矩阵。获得的矩阵是一个专门的二维阵列。 语法:

null
numpy.matrix(data, dtype = None) : 

参数:

data  : data needs to be array-like or string 
dtype : Data type of returned array. 
     

返回:

data interpreted as a matrix

# Python Program illustrating
# numpy.matrix class
import numpy as geek
# string input
a = geek.matrix( '1 2; 3 4' )
print ( "Via string input : " , a, "" )
# array-like input
b = geek.matrix([[ 5 , 6 , 7 ], [ 4 , 6 ]])
print ( "Via array-like input : " , b)


输出:

Via string input : 
 [[1 2]
 [3 4]] 


Via array-like input : 
 [[[5, 6, 7] [4, 6]]]
 

参考资料: https://docs.scipy.org/doc/numpy/reference/generated/numpy.mat.html#numpy.mat

注: 这些代码不会在联机IDE上运行。请在您的系统上运行它们以探索工作环境 . 本文由 莫希特·古普塔(Mohit Gupta_OMG) .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 写极客。组织 或者把你的文章寄去评论-team@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。

如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。

© 版权声明
THE END
喜欢就支持一下吧
点赞6 分享