What is the numpy.char.add() function from NumPy in Python?
Overview
The char.add() function in Python is simply used to return an element-wise string concatenation of two arrays, str, or Unicode.
Syntax
char.add(x1, x2)
Parameter value
The char.add() function takes the following mandatory parameter values.
x1: This represents the input array.x2: This represents the second input array to be concatenated with the first input array.
Return value
The char.add() function returns an array of strins or unicodes.
Code
import numpy as np# creatin the arraysx1 = ['Hi', 'Welcome', 'board']x2 = ['Pals', 'on', '!']# implementing the char.add() methodmyarray = np.char.add(x1, x2)print(myarray)
Explanation
- Line 1: We import the
numpymodule. - Lines 4-5: We create array variables
x1andx2. - Line 8: We use the
char.add()function to concatenate the arrays,x1andx2. The result is assigned to a variablemyarray. - Line 8: We print the variable
myarray.