python - How do I do conditional array arithmetic on a numpy array? -
I'm trying to get better hold of numpy arrays, so I have a sample question to ask them: < / P>
Say I'm called a lower array. I want to execute those values on those increments which are less than 0 and the rest leave alone, for example, if I was:
a = np.array ([ 1,2,3, -1, -2, -3])
I would like to return:
([1,2,3, 0, -1, -2])
What is the most compact syntax for this?
Thank you!
in [45]: a = np.array ([1,2,3, -1, -2, -3]) in [46]: one [a & lt; 0] + = 1 in [47]: One out [47]: array ([1, 2, 3, 0, -1, -2])
Comments
Post a Comment