Reputation: 5380
I have the following array:
array([[ 0. , -1.22474487, 1.40182605],
[ 1.22474487, 0. , -0.53916387],
[-1.22474487, 1.22474487, -0.86266219]])
What is the best way to parse each of its elements and assign a string depending on the value? For example: if value < 0 then set "LOW" else set "HIGH"?
Upvotes: 1
Views: 211
Reputation: 3363
If a
is your array
use
import numpy as np
np.where(a<0,'LOW','HIGH')
Edit: When you have 3 choices you can do something like
b = np.where(a < 0.,'LOW','HIGH').astype('S7')
c = np.where((-1. < a) & (a < 1.), 'MIDDLE',b)
Upvotes: 1