- Building Machine Learning Systems with Python
- Luis Pedro Coelho Willi Richert Matthieu Brucher
- 138字
- 2021-07-23 17:11:16
Indexing
Part of the power of NumPy comes from the versatile ways in which its arrays can be accessed.
In addition to normal list indexing, it allows you to use arrays themselves as indices by performing the following:
>>> a[np.array([2,3,4])]
array([77, 3, 4])
Coupled with the fact that conditions are also propagated to individual elements, we gain a very convenient way to access our data, using the following:
>>> a>4
array([False, False, True, False, False, True], dtype=bool)
>>> a[a>4]
array([77, 5])
By performing the following command, we can trim outliers:
>>> a[a>4] = 4
>>> a
array([0, 1, 4, 3, 4, 4])
As this is a frequent use case, there is a special clip function for it, clipping the values at both ends of an interval with one function call:
>>> a.clip(0,4)
array([0, 1, 4, 3, 4, 4])
推薦閱讀
- Aftershot Pro:Non-destructive photo editing and management
- 深入理解Spring Cloud與實戰
- 硬件產品經理成長手記(全彩)
- 3ds Max Speed Modeling for 3D Artists
- Artificial Intelligence Business:How you can profit from AI
- 計算機組裝維修與外設配置(高等職業院校教改示范教材·計算機系列)
- BeagleBone Robotic Projects
- 單片機原理與技能訓練
- Mastering Machine Learning on AWS
- 單片機原理及應用
- Mastering Quantum Computing with IBM QX
- Instant Website Touch Integration
- 計算機組成技術教程
- 創客電子:Arduino和Raspberry Pi智能制作項目精選
- FPGA進階開發與實踐