在没有循环的Numpy中添加子矩阵

Jas*_*les 4 python numpy

假设我得到了这个 a = np.arange(9).reshape((3,3))我想得到一个numpy数组,[9,12,15]其结果是

[0+3+6, 1+4+7, 2+5+8]
Run Code Online (Sandbox Code Playgroud)

Kas*_*mvd 5

你可以numpy.array.sum()通过传递函数来使用函数axis=0:

>>> a.sum(axis=0)
array([ 9, 12, 15])
Run Code Online (Sandbox Code Playgroud)