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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。