VOOZH about

URL: https://www.geeksforgeeks.org/python/repeat-all-the-elements-of-a-numpy-array-of-strings/

⇱ Repeat all the Elements of a NumPy Array of Strings - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Repeat all the Elements of a NumPy Array of Strings

Last Updated : 27 Sep, 2025

In NumPy, you can easily repeat each string in an array multiple times. The function numpy.char.multiply() allows you to repeat every element in a string array by a given number. This is useful when performing text preprocessing, string manipulation or data augmentation.

Example: Here’s a simple example that repeats each string 2 times.


Output
['OneOne' 'TwoTwo' 'ThreeThree']

Syntax

numpy.char.multiply(a, i)

Parameters:

  • a: Input array of strings.
  • i: Number of times each string is repeated.

Return Value: Returns a new array where each string is repeated i times.

Examples

Example 1: In this example, we repeat each string in the array 3 times.


Output
['LucaLucaLuca' 'SofiaSofiaSofia' 'HiroshiHiroshiHiroshi'
 'ElenaElenaElena' 'MateoMateoMateo']

Example 2: In this example, we create an array and repeat each element 2 times.


Output
['GeeksGeeks' 'forfor' 'GeeksGeeks']

Example 3: In this example, instead of np.char.multiply(), we use a Python list comprehension to repeat the strings.


Output
['PythonPython' 'isis' 'funfun']

Explanation: Each string is multiplied manually using s * n, then stored in a NumPy array. 

Comment