I have a numpy array :
a= [1,2,3,4,5,6]
I need to do some sort of string multiplication on this array as follows :
2*string(a) = [1,1,2,2,3,3,4,4,5,5,6,6]
Is there any way to do this in numpy?
Thanks
I have a numpy array :
a= [1,2,3,4,5,6]
I need to do some sort of string multiplication on this array as follows :
2*string(a) = [1,1,2,2,3,3,4,4,5,5,6,6]
Is there any way to do this in numpy?
Thanks
You could use np.repeat:
import numpy as np
a= [1,2,3,4,5,6]
result = np.repeat(a, 2)
print(result)
Output
[1 1 2 2 3 3 4 4 5 5 6 6]
Use numpy repeat:
a = np.array([1,2,3,4,5,6])
print(np.repeat(a,2))
Which gives:
[1 1 2 2 3 3 4 4 5 5 6 6]