首页 > 解决方案 > 如何理解一维数组和二维数组的 numpy dot 生成的维度变化?

问题描述

我有两个数组,a 和 b。

In [168]: a.shape
Out[168]: (20, 3)

In [169]: b.shape
Out[169]: (20,)

这两者的点积是

In [171]: numpy.dot(b, a).shape
Out[171]: (3,)

我不明白为什么要得到(3,)。a 和 b到底有什么numpy.dot作用?

据我了解,背后的机制可能是这样的:

numpy.dot(a.T, b)

这是有道理的,因为(3, 20) * (20,) -> (3,). 但为什么numpy.dot(b, a),,(20,) * (20, 3)也得到(3,)

标签: pythonarraysnumpy

解决方案


推荐阅读