- Building Machine Learning Systems with Python
- Luis Pedro Coelho Willi Richert Matthieu Brucher
- 93字
- 2021-07-23 17:11:16
Handling nonexistent values
The power of NumPy's indexing capabilities comes in handy when preprocessing data that we have just read in from a text file. Most likely, this will contain invalid values that we will mark as not being real numbers, using numpy.NAN, as shown in the following code:
>>> # let's pretend we have read this from a text file:
>>> c = np.array([1, 2, np.NAN, 3, 4])
array([ 1., 2., nan, 3., 4.])
>>> np.isnan(c)
array([False, False, True, False, False], dtype=bool)
>>> c[~np.isnan(c)]
array([ 1., 2., 3., 4.])
>>> np.mean(c[~np.isnan(c)])
2.5
推薦閱讀
- 現代辦公設備使用與維護
- 深入淺出SSD:固態存儲核心技術、原理與實戰(第2版)
- INSTANT ForgedUI Starter
- Artificial Intelligence Business:How you can profit from AI
- 計算機組裝與維護(第3版)
- CC2530單片機技術與應用
- 單片機系統設計與開發教程
- Blender Quick Start Guide
- Arduino項目開發:智能生活
- 單片機原理及應用
- Blender for Video Production Quick Start Guide
- Corona SDK Mobile Game Development:Beginner's Guide
- FPGA進階開發與實踐
- ActionScript Graphing Cookbook
- Learn Qt 5