numpy.defchararray.multiply() in Python
numpy.core.defchararray.multiply(arr, n): Concatenates strings ‘n’ times element-wise.
Parameters:
arr : array-like or string.
n : [array-like] no. of times we want to concatenate.Returns : Concatenated String ‘n’ times element-wise.
Code #1:
# Python Program illustrating # numpy.char.multiply() method import numpy as np arr1 = ['eAAAa', 'ttttds', 'AAt'] arr2 = ['11sf', 'sdsf2', '1111f2'] print ("\narr1 : ", arr1) print ("\narr2 : ", arr2) print ("\narr1 : ", np.char.multiply(arr1, 2)) # Seperate multiplication print ("\narr1 : ", np.char.multiply(arr1, [2, 4, 3])) print ("\narr2 : ", np.char.multiply(arr2, 3)) |
chevron_right
filter_none
Output:
arr1 : ['eAAAa', 'ttttds', 'AAt'] arr2 : ['11sf', 'sdsf2', '1111f2'] arr1 : ['eAAAaeAAAa' 'ttttdsttttds' 'AAtAAt'] arr1 : ['eAAAaeAAAa' 'ttttdsttttdsttttdsttttds' 'AAtAAtAAt'] arr2 : ['11sf11sf11sf' 'sdsf2sdsf2sdsf2' '1111f21111f21111f2']
Code #2:
# Python Program illustrating # numpy.char.multiply() method import numpy as np arr1 = 'This is geeks 'arr2 = 'for geeks ' print ("\narr1 : ", np.char.multiply(arr1, 2)) print ("\narr2 : ", np.char.multiply(arr2, 4)) |
chevron_right
filter_none
Output:
arr1 : This is geeks arr2 : for geeks arr1 : This is geeks This is geeks arr2 : for geeks for geeks for geeks for geeks
Recommended Posts:
- Python | Index of Non-Zero elements in Python list
- Python | Convert list to Python array
- Important differences between Python 2.x and Python 3.x with examples
- Python | Merge Python key values to list
- Reading Python File-Like Objects from C | Python
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Add Logging to Python Libraries
- Python | Sort Python Dictionaries by Key or Value
- Python | Add Logging to a Python Script
- Python | Visualizing O(n) using Python
- JavaScript vs Python : Can Python Overtop JavaScript by 2020?
- Python | a += b is not always a = a + b
- abs() in Python
- pow() in Python
- Python vs PHP
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



