numpy 创建矩阵、组合矩阵

import numpy as np


# 创建矩阵
m1 = np.mat("1 2 3;1 3 4;1 4 5")
# print(m1)
# print(type(m1))

m2 = np.mat([[2, 2, 3],[2, 3, 4],[2, 4, 5]])
# print(m2)
# print(type(m2))
# print(m2.ndim)

# matrix 是复制,浪费空间
m3 = np.matrix([[3, 2, 3],[3, 3, 4],[3, 4, 5]])
# print(m3)
# print(type(m3))


# 组合矩阵
# m4 = np.bmat([[m1, m2], [m2, m3]])
# print(m4)
# m5 = np.bmat("m1,m2;m2,m3")
# print(m5)

arr6 = np.arange(4).reshape(2, 2)
arr7 = np.arange(1, 5).reshape(2, 2)
arr8 = np.arange(2, 6).reshape(2, 2)
arr9 = np.arange(3, 7).reshape(2, 2)
# print(arr6,'\n')
# print(arr7,'\n')
# print(arr8,'\n')
# print(arr9,'\n')

m6 = np.bmat('arr6,arr7;arr8,arr9')
# print(m6)



# import numpy as np
#
#
# m1 = np.mat('1,2,3;1,3,4;1,4,5')
# # print(m1)
#
# m2 = np.mat([[2,2,3],[2,3,4],[2,4,5]])
# # print(m2)
# # print(type(m2))
#
# m3 = np.matrix('3,2,3;3,3,4;3,4,5')
# # print(m3)
#
# # m4 = np.bmat('m1,m2;m2,m3')
# # print(m4)
#
# # m5 = np.bmat([[m1,m2],[m2,m3]])
# # print(m5)

你可能感兴趣的:(数据分析)