Thursday, October 2, 2025
HomeLanguagesnumpy.char.multiply() function in Python

numpy.char.multiply() function in Python

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




# importing the module
import numpy as np
  
# created an array
arr1 = np.array(['Geeks'])
print("Original Array :")
print(arr1)
  
# number of times to be repeated
i = 3
  
# using the char.multiply() method
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




# importing the module
import numpy as np
  
# created an array
arr1 = np.array(['Geeks', 'for', 'Geeks'])
print("Original Array :")
print(arr1)
  
# number of times to be repeated
i = 2
  
# using the char.multiply() method
arr2 = np.char.multiply(arr1, i)
print("\nNew array :")
print(arr2)


Output :

Original Array :
['Geeks' 'for' 'Geeks']

New array :
['GeeksGeeks' 'forfor' 'GeeksGeeks']
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32330 POSTS0 COMMENTS
Milvus
85 POSTS0 COMMENTS
Nango Kala
6703 POSTS0 COMMENTS
Nicole Veronica
11867 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11926 POSTS0 COMMENTS
Shaida Kate Naidoo
6817 POSTS0 COMMENTS
Ted Musemwa
7078 POSTS0 COMMENTS
Thapelo Manthata
6775 POSTS0 COMMENTS
Umr Jansen
6774 POSTS0 COMMENTS