numpy.matrix(data,dtype = None):
此类从数据字符串或array-like对象返回矩阵。获得的矩阵是专门的2D数组。
参数:
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 : \n", a, "\n\n")
# array-like input
b = geek.matrix([[5, 6, 7], [4, 6]])
print("Via array-like input : \n", 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
相关用法
注:本文由纯净天空筛选整理自 numpy.matrix() in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。