
numpy学习
wavehaha
这个作者很懒,什么都没留下…
展开
-
numpy学习(一)数据拼接
1.np.r_及np.c使用方法:np.r_[a, b],np.c_[a, b],其中a,b为numpy.ndarray类型介绍:np.r_将矩阵维度为0的拼接,np.c_将矩阵维度为1的拼接(自己的理解)代码:a = np.array([[1, 2, 3], [7, 8, 9]])b = np.array([[4, 5, 6], [1, 2, 3]])c = np.c_[a, b]print(a)print(b)print(c)d = np.array([1, 2, 3])e =原创 2021-09-05 16:37:47 · 626 阅读 · 0 评论 -
TypeError: Cannot interpret ‘4‘ as a data type
TypeError: Cannot interpret ‘4’ as a data type问题:在写代码时,self.observations = np.zeros((self.max_size, state_dim),其中self.max_size和state_dim分别是两个参数,结果报错:TypeError: Cannot interpret '4' as a data type分析:numpy.zeros()参数为:numpy.zeros(shape, dtype=float, order原创 2022-05-11 15:17:39 · 3501 阅读 · 0 评论 -
numpy学习(二)矩阵乘法
numpy的5种乘法::矩阵中的数据连乘(np.prod):逐元素相乘(*):矩阵乘(dot):叉乘(np.cross):外乘(np.outer)代码:###################l1 = [[1, 2, 3], [4, 5, 6]]l2 = np.array(l1)for i in range(len(l1)): l3 = [np.prod(l2[i])] print(l3)#################a = mat([[1, 2, 3], [4,原创 2021-09-05 16:40:29 · 1866 阅读 · 0 评论