我在找np.add.at()
的二维版本。在
预期的行为如下。在
augend = np.zeros((10, 10))
indices_for_dim0 = np.array([1, 5, 2])
indices_for_dim1 = np.array([5, 3, 1])
addend = np.array([1, 2, 3])
### some procedure substituting np.add.at ###
assert augend[1, 5] == 1
assert augend[5, 3] == 2
assert augend[2, 1] == 3
任何建议都会有帮助!在
Oneliner公司:
当对
np.add.at
使用2d数组时,indices
必须是一个元组,其中tuple[0]
包含所有第一个坐标,tuple[1]
包含所有第二个坐标。在您可以按原样多维使用^{} 。
indices
参数在说明中包含以下内容:所以:
更简单地说:
^{pr2}$如果您真的很担心多维方面,并且augend是一个普通的连续C顺序数组,那么可以使用^{} 和{a3}在1D视图上执行操作:
相关问题 更多 >
编程相关推荐