Open In App

numpy.char.add() function in Python

Last Updated : 29 Aug, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

The add() method of the char class in the NumPy module is used for element-wise string concatenation for two arrays of str or unicode.

numpy.char.add()

Syntax : numpy.char.add(x1, x2)
Parameters :

  • x1 : first array to be concatenated (concatenated at the beginning)
  • x2 : second array to be concatenated (concatenated at the end)

Returns : Array of strings or unicode

Example 1 : Using the method on 2 single element string arrays.

Python3
# importing the module
import numpy as np

# create the arrays
x1 = ['Hello']
x2 = ['World']
print("The arrays are : ")
print(x1)
print(x2)

# using the char.add() method
result = np.char.add(x1, x2)
print("\nThe concatenated array is :")
print(result)

Output :

The arrays are : 
['Hello']
['World']

The concatenated array is :
['HelloWorld']


Example 2 : Using the method on 2 multiple elements string arrays.

Python3
# importing the module
import numpy as np

# create the arrays
x1 = ['Hello', 'to', 'all']
x2 = ['Geeks', 'for', 'Geeks']
print("The arrays are : ")
print(x1)
print(x2)

# using the char.add() method
result = np.char.add(x1, x2)
print("\nThe concatenated array is :")
print(result)

Output :

The arrays are : 
['Hello', 'to', 'all']
['Geeks', 'for', 'Geeks']

The concatenated array is :
['HelloGeeks' 'tofor' 'allGeeks']



Article Tags :
Practice Tags :

Similar Reads

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy