- Python Data Analysis
- Ivan Idris
- 127字
- 2021-08-05 17:31:51
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 (have a look at slicing1d.py
in this book's code bundle):
In: a = arange(9) In: a[3:7] Out: array([3, 4, 5, 6])
We can choose elements from indexes the 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])
推薦閱讀
- 小型電動(dòng)機(jī)實(shí)用設(shè)計(jì)手冊(cè)
- 大學(xué)計(jì)算機(jī)應(yīng)用基礎(chǔ)
- 運(yùn)動(dòng)控制器與交流伺服系統(tǒng)的調(diào)試和應(yīng)用
- 工業(yè)機(jī)器人運(yùn)動(dòng)仿真編程實(shí)踐:基于Android和OpenGL
- 基于企業(yè)網(wǎng)站的顧客感知服務(wù)質(zhì)量評(píng)價(jià)理論模型與實(shí)證研究
- Spatial Analytics with ArcGIS
- 未來(lái)學(xué)徒:讀懂人工智能飛馳時(shí)代
- Hands-On DevOps
- Practical AWS Networking
- 數(shù)據(jù)清洗
- PostgreSQL 10 High Performance
- 仿龜機(jī)器人的設(shè)計(jì)與制作
- 運(yùn)動(dòng)控制器及數(shù)控系統(tǒng)的工程應(yīng)用
- 從虛擬化到云計(jì)算
- 仿蛇機(jī)器人的設(shè)計(jì)與制作