Lets say I have arrays a and b
a = np.array([1,2,3])
b = np.array([\'red\',\'red\',\'red\'])
If I were to apply s
A marginal improvement on your current approach (which is potentially very wasteful in space):
import numpy as np
a = np.array([1,2,3])
b = np.array(['red','red','red'])
replacement = "blue"
b = b.astype('
This accounts for strings already in the array, so the allocated space only increases if the replacement is longer than all existing strings in the array.