Replacing values in numpy array based on multiple conditions without using any loops
Indeed it takes 3 parameters:
x = np.where(x > 0 , x, 1)
I have array:
x = np.array([1, 41, 32, 2, -8, 0, -97, 11])
If x[i] > 0, x[i] = 1
If x[i] < 0, x[i] = -1
If x[i] == 0, x[i] = 0
So expected output:
x = np.array([1, 1, 1, 1, -1, 0, -1, 1])
Is there a way to do this with a one liner in numpy without any loops? I wanted to use np.where but it only takes 2 conditions whereas I have 3. Thanks.