Dave31415 - 1 year ago 162

Python Question

Is this a bug?

`import numpy as np`

a1=np.array(['a','b'])

a2=np.array(['E','F'])

In [20]: add(a1,a2)

Out[20]: NotImplemented

I am trying to do element-wise string concatenation. I thought Add() was the way to do it in numpy but obviously it is not working as expected.

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

This can be done using numpy.core.defchararray.add. Here is an example:

```
>>> import numpy as np
>>> a1 = np.array(['a', 'b'])
>>> a2 = np.array(['E', 'F'])
>>> np.core.defchararray.add(a1, a2)
array(['aE', 'bF'],
dtype='<U2')
```

There are other useful string operations available for NumPy data types.

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**