以下為大家分享一篇Numpy遮罩式陣列詳解,具有很好的參考價值,希望對大家有幫助。一起過來看看吧
數據很大形況下是凌亂的,並且含有空白的或者無法處理的字符,掩碼式數組可以很好的忽略殘缺的或者是無效的數據點。遮罩式數組由一個正常數組與一個布林數組組成,若在布爾數組中為Ture,則表示正常數組中對應下標的值無效,反之False表示對應正常數組的值有效。
建立方法為,先建立一個布林型數組,然後透過numpy.ma子程式包提供的函數來建立遮罩式數組,遮罩式數組提供了各種所需函數。
建立實例如下:
#import numpy as np origin = np.arange(16).reshape(4,4) #生成一个4×4的矩阵 np.random.shuffle(origin) #随机打乱矩阵元素 random_mask = np.random.randint(0,2,size=origin.shape)#生成随机[0,2)的整数的4×4矩阵 mask_array = np.ma.array(origin,mask=random_mask)#生成掩码式矩阵 print(mask_array)
結果如下:
[[12 13 -- 15] [8 9 10 --] [-- -- -- 3] [-- 5 6 --]]
用於:
1.對負數取對數
import numpy as np triples = np.arange(0,10,3)#每隔3取0到10中的整数,(0,3,6,9) signs = np.ones(10)#(1,1,1,1,1,1,1,1,1) signs[triples] = -1#(-1,1,1,-1,1,1,-1,1,1,-1) values = signs * 77#(-77,77,77,-77,77,77,-77,77,77,-77) ma_log = np.ma.log(values)#掩码式取对数 print(ma_log)
[-- 4.343805421853684 4.343805421853684 -- 4.343805421853684
4.343805421853684 -- 4.343805421853684 4.343805421853684 --]
2.忽略極值
import numpy as np
inside = np.ma.masked_outside(array,min,max)
相關推薦:
詳談Numpy中陣列重塑、合併與分割方法
numpy中實作ndarray陣列傳回符合特定條件的索引方法
#以上是Numpy掩碼式數組詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!

SlicingaPythonlistisdoneusingthesyntaxlist[start:stop:step].Here'showitworks:1)Startistheindexofthefirstelementtoinclude.2)Stopistheindexofthefirstelementtoexclude.3)Stepistheincrementbetweenelements.It'susefulforextractingportionsoflistsandcanuseneg

numpyallowsforvariousoperationsonArrays:1)basicarithmeticlikeaddition,減法,乘法和division; 2)evationAperationssuchasmatrixmultiplication; 3)element-wiseOperations wiseOperationswithOutexpliitloops; 4)

Arresinpython,尤其是Throughnumpyandpandas,weessentialFordataAnalysis,offeringSpeedAndeffied.1)NumpyArseNable efflaysenable efficefliceHandlingAtaSetSetSetSetSetSetSetSetSetSetSetsetSetSetSetSetsopplexoperationslikemovingaverages.2)

列表sandnumpyArraysInpythonHavedIfferentMemoryfootprints:listSaremoreFlexibleButlessMemory-效率,而alenumpyArraySareSareOptimizedFornumericalData.1)listsStorReereReereReereReereFerenceStoObjects,with withOverHeadeBheadaroundAroundaround64byty64-bitsysysysysysysysysyssyssyssyssysssyssys2)

toensurepythonscriptsbehavecorrectlyacrycrosdevelvermations,分期和生產,USETHESTERTATE:1)Environment varriablesForsimplesettings,2)configurationfilesfilesForcomPlexSetups,3)dynamiCofforComplexSetups,dynamiqualloadingForaptaptibality.eachmethodoffersuniquebeneiquebeneqeniquebenefitsandrefitsandrequiresandrequiresandrequiresca

Python列表切片的基本語法是list[start:stop:step]。 1.start是包含的第一個元素索引,2.stop是排除的第一個元素索引,3.step決定元素之間的步長。切片不僅用於提取數據,還可以修改和反轉列表。

ListSoutPerformarRaysin:1)DynamicsizicsizingandFrequentInsertions/刪除,2)儲存的二聚體和3)MemoryFeliceFiceForceforseforsparsedata,butmayhaveslightperformancecostsinclentoperations。

toConvertapythonarraytoalist,usEthelist()constructororageneratorexpression.1)intimpthearraymoduleandcreateanArray.2)USELIST(ARR)或[XFORXINARR] to ConconverTittoalist,請考慮performorefformanceandmemoryfformanceandmemoryfformienceforlargedAtasetset。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

WebStorm Mac版
好用的JavaScript開發工具

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

Atom編輯器mac版下載
最受歡迎的的開源編輯器