官术网_书友最值得收藏!

One-dimensional slicing and indexing

Slicing of one-dimensional NumPy arrays works just like the slicing of standard Python lists. Let's define an array containing the numbers 0, 1, 2, and so on up to and including 8. We can select a part of the array from indexes 3 to 7, which extracts the elements of the arrays 3 through 6:

In: a = np.arange(9) 
In: a[3:7] 
Out: array([3, 4, 5, 6]) 

We can choose elements from an index of 0 to 7 with an increment of 2:

In: a[:7:2] 
Out: array([0, 2, 4, 6]) 

Just as in Python, we can use negative indices and reverse the array:

In: a[::-1] 
Out: array([8, 7, 6, 5, 4, 3, 2, 1, 0]) 
主站蜘蛛池模板: 泌阳县| 剑河县| 澄迈县| 咸丰县| 星子县| 六盘水市| 辽宁省| 桂林市| 蒙自县| 井研县| 桂东县| 延津县| 怀仁县| 湟源县| 高阳县| 防城港市| 文水县| 锦州市| 张家口市| 嵩明县| 南木林县| 新巴尔虎右旗| 玉门市| 外汇| 宜兴市| 休宁县| 堆龙德庆县| 博湖县| 曲松县| 犍为县| 赤峰市| 天等县| 海丰县| 孝义市| 石阡县| 正定县| 富裕县| 茂名市| 五家渠市| 鄄城县| 呼玛县|