import numpy as np
a = np.array(["a", "b", "c"])
b = np.array(["A", "B", "C"])
a+b
>>TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('<U1') dtype('<U1') dtype('<U1')
Will be like this
import numpy as np
c = np.array(["a", "b", "c"], dtype=np.object)
d = np.array(["A", "B", "C"], dtype=np.object)
c+d
>>array(['aA', 'bB', 'cC'], dtype=object)
I got it
Let's use map
import numpy as np
a = np.array(["a", "b", "c"])
b = np.array(["A", "B", "C"])
np.array(list(map("".join, zip(a, b))))
>>array(['aA', 'bB', 'cC'], dtype='<U2')
The object type is convenient!
Other methods are also introduced https://stackoverrun.com/ja/q/2619737
About Numpy data types https://note.nkmk.me/python-numpy-dtype-astype/
Recommended Posts