Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

numpy.defchararray.add() in Python

  • Last Updated : 28 Nov, 2018

numpy.core.defchararray.add(arr1, arr2): Concatenates two strings element-wise.

Parameters:
arr1 : array-like or string.
arr2 : array-like or string.

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

Returns : Concatenates String.



Code #1:




# Python Program illustrating 
# numpy.char.add() method 
import numpy as np 
  
arr1 = ['vdteteAAAa', 'AAAttttds', 'AAaxtt']
arr2 = ['1111sfdsf', '1111111sdsf2', '1111111sfsf2']
  
print ("\narr1 : ", arr1)
print ("\narr2 : ", arr2)
  
print ("\narr1 + arr2\n", np.char.add(arr1, arr2))
print ("\narr2 + arr1\n", np.char.add(arr2, arr1))

Output:

arr1 :  ['vdteteAAAa', 'AAAttttds', 'AAaxtt']

arr2 :  ['1111sfdsf', '1111111sdsf2', '1111111sfsf2']

arr1 + arr2
 ['vdteteAAAa1111sfdsf' 'AAAttttds1111111sdsf2' 'AAaxtt1111111sfsf2']

arr2 + arr1
 ['1111sfdsfvdteteAAAa' '1111111sdsf2AAAttttds' '1111111sfsf2AAaxtt']

 
Code #2:




# Python Program illustrating 
# numpy.char.add() method 
import numpy as np 
  
arr1 = 'This is geeks '
arr2 = 'for geeks '
  
print ("\narr1 + arr2\n", np.char.add(arr1, arr2))
print ("\narr2 + arr1\n", np.char.add(arr2, arr1))

Output:

arr1 + arr2
 This is geeks for geeks 

arr2 + arr1
 for geeks This is geeks 



My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!