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 = [
I found another solution with the numpy function place. (Documentation here)
place
Using it on your example:
>>> a = np.array([1,2,2,1]).reshape(2,2) >>> a array([[1, 2], [2, 1]]) >>> np.place(a, a==1, 0) >>> np.place(a, a==2, 10) >>> a array([[ 0, 10], [10, 0]])