[英]Extracting indices from numpy array python
I want the last 4 values of this equation. 我想要这个等式的最后4个值。
Is there a better way to this in one step, like modifying the equation or another extraction technique other than using delete
有没有更好的方法一步到位,比如修改方程或除了使用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]
print n[-4::]
will print the last 4 elements. 将打印最后4个元素。 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. 您可以从正面或背面为数组建立索引。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.