You should resist the urge to think of numpy arrays as having rows
and columns, but instead consider them as having dimensions and
shape. This is an important point which differentiates np.array and np.matrix:
An n-D array can only use n integer(s) to represent its shape.
Therefore, a 1-D array only uses 1 integer to specify its shape.
In practice, combining calculations between 1-D and 2-D arrays is not
a problem for numpy, and syntactically clean since @ matrix
operation was introduced in Python 3.5. Therefore, there is rarely a
need to resort to np.matrix in order to satisfy the urge to see
expected row and column counts.
我复制了我今天早些时候写的answer的一部分:
与点积有关的向量和矩阵形状的大多数规则的存在主要是为了有一个连贯的方法,可以扩展到更高的张量阶。但在处理一阶(向量)和二阶(矩阵)张量时,它们并不十分重要。而这些订单正是绝大多数
numpy
用户所需要的。在因此,}会针对这些顺序进行优化(数学上和输入解析),始终在第一个轴的最后一个轴上求和,以及第二个轴的第二个到最后一个轴(如果适用)。“如果适用”是一种白痴证明,以确保输出是在绝大多数情况下,即使形状不符合技术要求。在
@
和{同时,我们这些使用高阶张量的人,则被归为},它们都有关于维数匹配的所有琐碎的小规则。在
np.tensordot
或{这种行为是故意的。The NumPy docs状态:
相关问题 更多 >
编程相关推荐