Phi*_*erg 10 python numpy variable-assignment slice
为什么以下几行不能按预期工作?
import numpy as np
a = np.array([0,1,2,1,1])
a[a==1][1:] = 3
print a
>>> [0 1 2 1 1]
# I would expect [0 1 2 3 3]
Run Code Online (Sandbox Code Playgroud)
这是一个'错误'还是有另一种推荐方式?
另一方面,以下工作:
a[a==1] = 3
print a
>>> [0 3 2 3 3]
Run Code Online (Sandbox Code Playgroud)
干杯,菲利普