numpy.defchararray.add () in Python

NumPy | Python Methods and Functions

numpy.core.defchararray.add (arr1, arr2) : numpy.core.defchararray.add (arr1, arr2) two lines element by element.

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

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 ( "arr1:" , arr1)

print ( "arr2:" , arr2)

 

print ( "arr1 + arr2" , np.char.add (arr1, arr2))

print ( "arr2 + arr1" , np.char.add (arr2, arr1))

Exit:

 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 ( "arr1 + arr2" , np.char.add (arr1, arr2))

print ( "arr2 + arr1" , np.char.add (arr2, arr1))

Exit:

 arr1 + arr2 This is geeks for geeks arr2 + arr1 for geeks This is geeks 




Get Solution for free from DataCamp guru