import numpy as np # array a = np.array(["a b c", "d e f", "h i j"]) # function replace_space = np.vectorize(lambda x: x.replace(" ", "_")) # response print(replace_space(a)) # will return: ['a_b_c' 'd_e_f' 'h_i_j']