Q:

Write a NumPy program to repeat all the elements three times of a given array of string

0

Write a NumPy program to repeat all the elements three times of a given array of string.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np
x1 = np.array(['Python', 'PHP', 'Java', 'C++'], dtype=np.str)
print("Original Array:")
print(x1)
new_array = np.char.multiply(x1, 3)
print("New array:")
print(new_array)

Sample Input:

(['Python', 'PHP', 'Java', 'C++'], dtype=np.str)

Sample Output:

Original Array:
['Python' 'PHP' 'Java' 'C++']
New array:
['PythonPythonPython' 'PHPPHPPHP' 'JavaJavaJava' 'C++C++C++']

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now