numpy.char.multiply() function in Python
Last Updated :
29 Aug, 2020
The multiply() method of the char class in the NumPy module is used for element-wise string multiple concatenation.
numpy.char.multiply()
Syntax : numpy.char.multiply(a, i)
Parameters :
- a : array of str or unicode
- i : number of times to be repeated
Returns : Array of strings
Example 1 : Using the method on a single element string array.
Python3
import numpy as np
arr1 = np.array([ 'Geeks' ])
print ( "Original Array :" )
print (arr1)
i = 3
arr2 = np.char.multiply(arr1, i)
print ( "\nNew array :" )
print (arr2)
|
Output :
Original Array :
['Geeks']
New array :
['GeeksGeeksGeeks']
Example 2 : Using the method on multiple elements string array.
Python3
import numpy as np
arr1 = np.array([ 'Geeks' , 'for' , 'Geeks' ])
print ( "Original Array :" )
print (arr1)
i = 2
arr2 = np.char.multiply(arr1, i)
print ( "\nNew array :" )
print (arr2)
|
Output :
Original Array :
['Geeks' 'for' 'Geeks']
New array :
['GeeksGeeks' 'forfor' 'GeeksGeeks']
Share your thoughts in the comments
Please Login to comment...