I have a boolean array like such
bool_arr = [True, True, False]
And I want to map two Strings onto each boolean value
string_arr = ['r', 'r, 'k']
How would I map this using numpy?
Vectorized approaches using indexing -
bool_arr = np.array([True, True, False]) # Input boolean array
strings = np.array(['k','r']) # Input array of strings for mapping
out = np.take(strings, bool_arr)
out = np.take(strings, bool_arr.astype(int))
out = strings[bool_arr.astype(int)]
Using np.where if we need to choose between just two strings -
np.where(bool_arr, 'r','k')
numpyarrays?