user3084006
user3084006

Reputation: 5564

Extracting indices from numpy array python

I want the last 4 values of this equation.

Is there a better way to this in one step, like modifying the equation or another extraction technique other than using delete

a=5
d=2

n = np.cumsum(d ** np.arange(1, a+1))
print 'n=', n
n = np.delete(n,0)
print 'n extracted=', n

n= [ 2  6 14 30 62]
n extracted= [ 6 14 30 62]

Upvotes: 2

Views: 281

Answers (1)

Cory Kramer
Cory Kramer

Reputation: 117856

print n[-4::] 

will print the last 4 elements. You can do all kinds of array slicing like this, the above was just an example. You can index the array from the front or the back.

Upvotes: 7

Related Questions