Create a matrix

table of Contents

1.mat()

2.matrix()

3. BMAT combining matrix ()

(1) The matrix composition directly into a new matrix  

(2) a combination of a matrix array


1.mat()

copy the default value is False so we recommend using the mat () to create a matrix

 You can use a string to create a form, you can also use the list to create a form of

import numpy as np
# 字符串
m1=np.mat('1 2 3;2 3 4;3 4 5')
print('m1:',m1)
print(type(m1)) # <class 'numpy.matrix'>
# 列表
m2=np.mat([[1,2,3],[2,3,4],[3,4,5]])
print('m2:',m2)

2.matrix()

The default value is True copy parameters

import numpy as np
# 字符串
m3=np.matrix('1 2 3;2 3 4;3 4 5')
print('m3:',m3)
print(type(m3)) # <class 'numpy.matrix'>
# 列表
m4=np.matrix([[1,2,3],[2,3,4],[3,4,5]])
print('m4:',m4)

3. BMAT combining matrix ()

(1) The matrix composition directly into a new matrix  

# 字符串
m3=np.bmat('m1 m2;m2 m1')
print('m3:',m3)
# 列表
m4=np.bmat([[m1,m2],[m2,m1]])
print('m4:',m4)

(2) a combination of a matrix array

import numpy as np
arr1=np.arange(4).reshape(2,2)
arr2=np.arange(1,5).reshape(2,2)
arr3=np.arange(2,6).reshape(2,2)
arr4=np.arange(3,7).reshape(2,2)
m=np.bmat('arr1,arr2,arr3,arr4')
print(m)
print(type(m)) # <class 'numpy.matrix'>

 

Guess you like

Origin blog.csdn.net/g_optimistic/article/details/92000479