Issue
How do I create a sequence of increasing numbers based on x? I might have arrays for x of which have 100,000 values so I cannot assume what x is.
x = np.array([0,2,9,6,1,3,6,2,8,6,10])
Desired array:
print(y)
np.array([1,2,3,4,5,6,7,8,9,10,11])
Solution
I can't comment with my rep but I think we need more info. Are you essentially looking for the range of numbers that corresponds to the length of x
but starting at 1? If so you could do:
import numpy as np
x = np.array([0,2,9,6,1,3,6,2,8,6,10])
y = np.array([i+1 for i in range(len(x))])
print(y)
Edit:
@obchardon brings up a great point in the comments. Here is how you would use np.arange()
:
import numpy as np
x = np.array([0,2,9,6,1,3,6,2,8,6,10])
y = np.arange(1,len(x)+1)
print(y)
Answered By - noahtf13
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.