NumPy: add() function
numpy.core.defchararray.add() function
The numpy.core.defchararray.add() function is used to create element-wise string concatenation for two given arrays of str or unicode.
The two given arrays must have the same shape.
Version: 1.15.0
Syntax:
numpy.core.defchararray.add(x1, x2)
Parameter:
Name | Description | Required / Optional |
---|---|---|
x1: array_like of str or unicode | Input array. | Required |
x2: array_like of str or unicode | Input array | Required |
Return value:
add [ndarray] Output array of string_ or unicode_, depending on input types of the same shape as x1 and x2.
Note:
The 'chararray' class exists for backwards compatibility with Numarray, it is not recommended for new development. Starting from numpy 1.4, if one needs arrays of strings, it is recommended to use arrays of 'dtype' 'object_', 'string_' or 'unicode_', and use the free functions in the 'numpy.char' module for fast vectorized string operations.
Some methods will only be available if the corresponding string method is available in your version of Python.
The preferred alias for 'defchararray' is 'numpy.char'.
Example-1: numpy.char.add() function
>>> import numpy as np
>>> x1 = np.array(['p', 't'])
>>> x2 = np.array(['Y', 'H'])
>>> np.char.add(x1, x2)
array(['pY', 'tH'], dtype='<U2')
Pictorial Presentation:
Example-2: numpy.char.add() function
>> import numpy as np
>>> s1 = np.array(("Java"))
>>> s2 = np.array(("Script"))
>>> np.char.add(s1, s2)
array('JavaScript', dtype='<U10')
Pictorial Presentation:
Python - NumPy Code Editor:
Previous:
NumPy String operation Home
Next:
multiply()
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework