I have the following two numpy arrays:
a1
array(['T', 'T', 'T', ..., 'G', 'A', 'A'], dtype=object)
a2
array(['A', 'G', 'C', ..., 'A', 'T', 'G'], dtype=object)
I want to add each element from the two arrays. The following command works:
s = a1 + a2
s
array(['TA', 'TG', 'TC', ..., 'GA', 'AT', 'AG'], dtype=object)
But I get an error when trying to use numpy.char.add:
np.char.add(a1, a2)
TypeError: string operation on non-string array
Why does this happen?
np.add(a1,a2)works the same asa1+a2. This uses theaddmethod of each object.np.charfunctions apply string methods to numpy char dtypes. The result is similar