Thursday, July 23, 2026
HomeLanguagesnumpy.defchararray.multiply() in Python

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))
  
# Separate multiplication
print ("\narr1 : ", np.char.multiply(arr1, [2, 4, 3]))
print ("\narr2 : ", np.char.multiply(arr2, 3))


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 neveropen '
arr2 = 'for neveropen '
  
print ("\narr1 : ", np.char.multiply(arr1, 2))
print ("\narr2 : ", np.char.multiply(arr2, 4))


Output:

arr1 :  This is neveropen 
arr2 :  for neveropen 

arr1 :  This is neveropen This is neveropen 
arr2 :  for neveropen for neveropen for neveropen for neveropen 
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32520 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6902 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12114 POSTS0 COMMENTS
Shaida Kate Naidoo
7023 POSTS0 COMMENTS
Ted Musemwa
7265 POSTS0 COMMENTS
Thapelo Manthata
6980 POSTS0 COMMENTS
Umr Jansen
6971 POSTS0 COMMENTS