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

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
主站蜘蛛池模板: 满洲里市| 英超| 石首市| 丹凤县| 泸定县| 海伦市| 内江市| 星座| 大宁县| 新乡市| 衡南县| 禄丰县| 淳化县| 二连浩特市| 剑川县| 大英县| 昌吉市| 广平县| 侯马市| 哈密市| 鲁甸县| 灵台县| 垦利县| 尉氏县| 建瓯市| 额济纳旗| 宁夏| 潢川县| 灌南县| 乌什县| 龙岩市| 金乡县| 金湖县| 华容县| 滦南县| 马山县| 大埔区| 芜湖县| 秦安县| 松江区| 剑阁县|