- 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])
推薦閱讀
- Dreamweaver CS3網頁制作融會貫通
- 大數據改變世界
- Hadoop Real-World Solutions Cookbook(Second Edition)
- INSTANT Autodesk Revit 2013 Customization with .NET How-to
- Moodle Course Design Best Practices
- Implementing Splunk 7(Third Edition)
- 大數據時代
- Windows Server 2003系統安全管理
- 走近大數據
- 教育機器人的風口:全球發展現狀及趨勢
- Bayesian Analysis with Python
- ADuC系列ARM器件應用技術
- Access 2007數據庫入門與實例應用金典
- Hands-On Microservices with C#
- 軟件測試設計