Suppose you have a numpy array and a list:
>>> a = np.array([1,2,2,1]).reshape(2,2)
>>> a
array([[1, 2],
[2, 1]])
>>> b = [0, 10]
I'd like to replace values in an array, so that 1 is replaced by 0, and 2 by 10.
I found a similar problem here - http://mail.python.org/pipermail//tutor/2011-September/085392.html
But using this solution:
for x in np.nditer(a):
if x==1:
x[...]=x=0
elif x==2:
x[...]=x=10
Throws me an error:
ValueError: assignment destination is read-only
I guess that's because I can't really write into a numpy array.
P.S. The actual size of the numpy array is 514 by 504 and of the list is 8.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…