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

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]) 
主站蜘蛛池模板: 崇仁县| 怀柔区| 科尔| 资兴市| 永新县| 北京市| 婺源县| 成都市| 大厂| 苏尼特右旗| 南川市| 镇巴县| 博湖县| 博罗县| 新泰市| 惠安县| 台东县| 沙坪坝区| 青铜峡市| 彰武县| 交城县| 集安市| 海口市| 宁蒗| 岳西县| 太湖县| 慈利县| 兴仁县| 博湖县| 威远县| 儋州市| 尤溪县| 宁明县| 玉环县| 兰考县| 宜良县| 双流县| 阳新县| 保定市| 郎溪县| 突泉县|