1

I have the following array of strings as a numpy array:

filepaths = np.array(['Padma','Meghna','Jamuna'])

And I want to concatenate so that I should get the following :

 Padma-Meghna-Jamuna

I am doing the following, but not getting as expected:

 np.array([np.core.defchararray.join('-',a) for a in filepaths])


 array(['P-a-d-m-a', 'M-e-g-h-n-a', 'J-a-m-u-n-a'], 
  dtype='|S11')

Some hint would be helpful here

1 Answer 1

6

The defchararray.join operates on each element of the array, individually.

In [94]: '-'.join('padma')
Out[94]: 'p-a-d-m-a'

Just treat your array like a list:

In [93]: '-'.join(np.array(['Padma','Meghna','Jamuna']))
Out[93]: 'Padma-Meghna-Jamuna'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.