numpy.ma.filled()函數以數組形式返回輸入,其中掩碼數據被填充值替換。如果arr不是MaskedArray,則返回arr本身。如果arr是MaskedArray並且fill_value為None,則fill_value設置為arr.fill_value。
用法: numpy.ma.filled(arr, fill_value = None)
參數:
arr :[MaskedArray或數組]一個輸入對象。
fill_value :[標量,可選]填充值。默認為無。
Return :[ndarray]填充的數組。
代碼1:
# Python program explaining
# numpy.ma.filled() function
# importing numpy as geek
# and numpy.ma module as ma
import numpy as geek
import numpy.ma as ma
arr = geek.ma.array(geek.arange(4).reshape(2, 2),
mask =[[1, 0], [0, 1]])
gfg = arr.filled()
print (gfg)
輸出:
[[999999 1] [ 2 999999]]
代碼2:
# Python program explaining
# numpy.ma.filled() function
# importing numpy as geek
# and numpy.ma module as ma
import numpy as geek
import numpy.ma as ma
arr = geek.ma.array(geek.arange(9).reshape(3, 3),
mask =[[1, 0, 0], [1, 0, 0], [0, 0, 0]])
gfg = arr.filled()
print (gfg)
輸出:
[[999999 1 2] [999999 4 5] [ 6 7 8]]
相關用法
- Python Wand function()用法及代碼示例
- Python id()用法及代碼示例
- Python oct()用法及代碼示例
- Python sum()用法及代碼示例
- Python ord()用法及代碼示例
- Python str()用法及代碼示例
- Python hex()用法及代碼示例
- Python int()用法及代碼示例
- Python now()用法及代碼示例
- Python cmp()用法及代碼示例
- Python map()用法及代碼示例
- Python tell()用法及代碼示例
- Python dir()用法及代碼示例
- Python reversed()用法及代碼示例
- Python cmath.tan()用法及代碼示例
- Python vars()用法及代碼示例
- Python randint()用法及代碼示例
注:本文由純淨天空篩選整理自sanjoy_62大神的英文原創作品 numpy.ma.filled() function – Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。