一.matrix特殊属性解释 numpy中matrix有下列的特殊属性,使得矩阵计算更加容易 摘自 NumPy Reference Release 1.8.1 1.1 The N-dimensional array (ndarray) An ndarray is a (usually fixed-size) multidimensional container of items of the same type and size. 摘自 NumPy Reference Release 1.9.1
矩阵(Matrix)和数组(Array)的区别主要有以下两点: 矩阵只能为2维的,而数组可以是任意维度的. 矩阵和数组在数学运算上会有不同的结构. 代码展示 1.矩阵的创建 采用mat函数创建矩阵 class numpy.mat(data, dtype=None) (注释:Unlike matrix, asmatrix does not make a copy if the input is already a matrix or an ndarray. Equivalent to matrix
1.numpy乘法运算中"*"是数组元素逐个计算 >>> import numpy as np >>> a = np.array([[2,3],[3,4]]) >>> b = np.array([[3,4],[5,6]]) >>> c = a * b >>> c array([[ 6, 12], [15, 24]]) >>> 2.numpy乘法运算中dot是按照矩阵乘法的规则来运