1.

Write a program to repeat each of the elements five times for a given array.

Answer»

Sample Solution:-

import numpy as np
# Create Sample NumPy Array
arr = np.array(['i', 'love', 'NumPy', 'AND', 'interviewbit'], dtype=str)

transformed_array = np.char.multiply(arr, 5)
print("Transformed array:")
print(transformed_array)

Output:

Transformed array:
['iiiii' 'lovelovelovelovelove' 'NumPyNumPyNumPyNumPyNumPy'
'ANDANDANDANDAND'
'interviewbitinterviewbitinterviewbitinterviewbitinterviewbit']


Discussion

No Comment Found