1 # encoding:utf-8 2 3 import numpy as np 4 data1 = np.array([1, 2, 3, 4, 5]) 5 print(data1) 6 data2 = np.array([[1, 2], 7 [3, 4]]) 8 print(data2) 9 # 矩阵的维度 10 print(data1.shape, data2.shape) 11 # 全零矩阵和全一矩阵 12 print(np.zeros([2,3]), np.ones([2,2])) 13 # 更改矩阵中的元素 14 data2[1, 0] = 5 15 print(data2) 16 # 查看矩阵元素的值 17 print(data2[1, 1]) 18 # 矩阵的点乘、点除、对应相加和对应相减 19 data3 = np.ones([2, 3]) 20 print(data3*2) # 对应相乘 21 print(data3/3) 22 print(data3+2) 23 print(data3-2) 24 # 矩阵+和* 25 data4 = np.array([[1, 2, 3], [4, 5, 6]]) 26 print(data3+data4) 27 print(data3*data4)