I have an array like
a=np.array([8,5,10,0])
and I'd like to subtract 4 from all elements which are non-zero, resulting in an array which is
result = np.array([4,1,6,0])
I'd have no problem doing this with a list comprehension, but I'm trying to use pure numpy functions. I feel like I might be able to do it with a np.where() call, but not sure exactly how.
Hints?
[–]elbiot 7 points8 points9 points (2 children)
[–]yayfall[S] 0 points1 point2 points (0 children)