📜  Python中的 numpy.matrix()

📅  最后修改于: 2022-05-13 01:55:28.073000             🧑  作者: Mango

Python中的 numpy.matrix()

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

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 : \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