I have two arrays, and want to combine the ith elements in each one together:
import numpy as np
a = np.array(['a', 'b', 'c'])
b = np.array(['x', 'y', 'z'])
I want to return
array(['ax', 'by', 'cz'])
What is the function for this? Thx,
>>> import numpy as np
>>> a = np.array(['a', 'b', 'c'])
>>> b = np.array(['x', 'y', 'z'])
>>> c = np.array([i+j for i, j in zip(a, b)])
>>> c
array(['ax', 'by', 'cz'],
dtype='|S2')
@DSM makes the point that if a and b had dtype=object you could simply add the two arrays together:
>>> a = np.array(["a", "b", "c"], dtype=object)
>>> b = np.array(["x", "y", "z"], dtype=object)
>>> c = a + b
>>> c
array([ax, by, cz], dtype=object)
zip.a and b had dtype=object, then a+b would Just Work(tm). [Actually, I think either one would suffice.]