Counting the elements of an array and creating another array in Python
Question:
I have an array y
. I want to create another array x
which is based on the length of y
. I present the current and expected outputs.
import numpy as np
y=np.array([60. , 57.71689783, 43.92696073, 41.27856221, 52.87672123,
46.75800742, 40.36532134, 42.10047899, 44.65755342, 52.69407306,
48.49316507, 53.78, 55.0 ])
x=np.array([len(y)])
The current output is
array([13])
The expected output is
array([1,2,3,4,5,6,7,8,9,10,11,12,13])
Answers:
Try this… using arange
x=np.arange(1,len(y)+1)
I have an array y
. I want to create another array x
which is based on the length of y
. I present the current and expected outputs.
import numpy as np
y=np.array([60. , 57.71689783, 43.92696073, 41.27856221, 52.87672123,
46.75800742, 40.36532134, 42.10047899, 44.65755342, 52.69407306,
48.49316507, 53.78, 55.0 ])
x=np.array([len(y)])
The current output is
array([13])
The expected output is
array([1,2,3,4,5,6,7,8,9,10,11,12,13])
Try this… using arange
x=np.arange(1,len(y)+1)