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.