I want to exclude starting point from a array in python using numpy. How I can execute? For example I want to exclude 0, but want to continue from the very next real number(i.e want to run from greater than 0) following code x=np.linspace(0,2,10)
Kind of an old question but I thought I'll share my solution to the problem.
Assuming you want to get an array
[0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.]
you can make use of the endpoint option in np.linspace() and reverse the direction:
x = np.linspace(2, 0, 10, endpoint=False)[::-1]
the [::-1] reverses the array so that it ends up being in the desired sequence.
x=np.linspace(0,2,10)[1:] #remove the first element by indexing
print(x)
[0.22222222 0.44444444 0.66666667 0.88888889 1.11111111 1.33333333
1.55555556 1.77777778 2. ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With