我有一个像A这样的3D数组
A = np.random.randint(20,size=(4,2,2))
array([[[18, 8],
[ 2, 11]],
[[ 9, 8],
[ 9, 10]],
[[ 0, 1],
[10, 6]],
[[ 1, 8],
[ 4, 2]]])我想要做的是将一个函数应用于axis=0上的一些索引。例如,我想将A1和A3乘以2,再加上10。我知道一个选择是这样的:
for index in [1,3]:
A[index] = A[index]*2+10这就给出了:
array([[[18, 8],
[ 2, 11]],
[[28, 26],
[28, 30]],
[[ 0, 1],
[10, 6]],
[[12, 26],
[18, 14]]])但是我的原始数组的大小是(2500,300,300),并且我每次都需要将该函数应用于axis=0上的500个非连续索引。有没有一种更快、更有蟒蛇风格的方法呢?
https://stackoverflow.com/questions/44317324
复制相似问题