久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在矩陣中使用 numpy.sum 和 numpy.mean 時如何忽略值

How to ignore values when using numpy.sum and numpy.mean in matrices(在矩陣中使用 numpy.sum 和 numpy.mean 時如何忽略值)
本文介紹了在矩陣中使用 numpy.sum 和 numpy.mean 時如何忽略值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

在 numpy 中應用 sum 和 mean 時有沒有辦法避免使用特定值?

Is there a way to avoid using specific values when applying sum and mean in numpy?

例如,我想在計算結(jié)果時避免使用 -999 值.

I'd like to avoid, for instance, the -999 value when calculating the result.

In [14]: c = np.matrix([[4., 2.],[4., 1.]])

In [15]: d = np.matrix([[3., 2.],[4., -999.]])

In [16]: np.sum([c, d], axis=0)
Out[16]:
array([[   7.,    4.],
       [   8., -998.]])

In [17]: np.mean([c, d], axis=0)
Out[17]:
array([[   3.5,    2. ],
       [   4. , -499. ]])

推薦答案

使用掩碼數(shù)組:

>>> c = np.ma.array([[4., 2.], [4., 1.]])
>>> d = np.ma.masked_values([[3., 2.], [4., -999]], -999)

>>> np.ma.array([c, d]).sum(axis=0)
masked_array(data =
 [[7.0 4.0]
 [8.0 1.0]],
             mask =
 [[False False]
 [False False]],
       fill_value = 1e+20)

>>> np.ma.array([c, d]).mean(axis=0)
masked_array(data =
 [[3.5 2.0]
 [4.0 1.0]],
             mask =
 [[False False]
 [False False]],
       fill_value = 1e+20)

這篇關(guān)于在矩陣中使用 numpy.sum 和 numpy.mean 時如何忽略值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區(qū)域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據(jù)文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 亚洲精品一区二三区不卡 | 日一日操一操 | 亚洲精品v日韩精品 | aaa一区 | 国产在视频一区二区三区吞精 | 国产xxx在线观看 | 在线一区二区国产 | 深夜福利影院 | 日日操夜夜操天天操 | 一区二区日韩 | 欧美一区二区久久 | 91久久伊人 | 亚洲日韩视频 | 午夜男人的天堂 | 日韩视频一级 | 日本亚洲欧美 | 色爱综合网 | 少妇一级淫片免费放播放 | 一区二区精品 | www.99re| 91免费在线 | 欧美在线一区二区三区 | 亚洲看片 | 免费国产黄网站在线观看视频 | 中文字幕一区二区三区四区 | 精品毛片在线观看 | 久久成人一区 | 毛片在线视频 | 精品国产一二三区 | 亚洲午夜一区二区 | 雨宫琴音一区二区在线 | 99在线精品视频 | 国产视频二区在线观看 | av在线天天| 亚洲精品天堂 | av网站在线看 | 超碰在线亚洲 | 久久人人爽人人爽人人片av免费 | a级片播放| 亚洲综合中文字幕在线观看 | 久久综合久色欧美综合狠狠 |