If the number of objects in the selection tuple is less than N , then : is assumed for any subsequent dimensions.
An integer, i, returns the same values as i:i+1 except the dimensionality of the returned object is reduced by 1. In particular, a selection tuple with the p-th element an integer (and all other entries :) returns the corresponding sub-array with dimension N - 1.
X[i]是得到X的第i个列表
X[i,:]是从X的第i个列表中切片数据
你得到了相同的结果,但实际上它们是不同的。你知道吗
https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#basic-slicing-and-indexing
它们是一样的。如另一个答案所示,计时是不同的,但是时间在
ns
中,Python解析时间和函数调用的层次可以产生不同。但我欢迎任何基于numpy代码实际阅读的更正。你知道吗切片属性相同:
时间安排:
比较返回副本的时间(与视图相反):
列的索引也一样:
(对于一个更大的数组,我得到了相同的时间——支持这样一种观点,即任何时间差都发生在解析/设置过程中,而不是在视图的实际构造过程中。)
切片比较慢。我已经用%timeit证明了这一点。它测量执行时间。你知道吗
使用切片:
相关问题 更多 >
编程相关推荐