先決條件:numpy
此numpy內置函數可抑製包含二維數組中包含掩碼值的整個列。
Syntax: numpy.ma.compress_cols(arr)
Parameters:
arr:[array_like, MaskedArray]
- This parameter holds the array to operate on.
- The array must be a 2D array.
- If no array elements are masked, arr is interpreted as a MaskedArray with mask set to nomask.
返回:Returns the compressed array.
下麵是上述函數的實現。
範例1:
Python3
# importing numpy as geek
import numpy as geek
# defining an array with mask
arr = geek.ma.array(geek.arange(6).reshape(2, 3),
mask=[[1, 0, 0], [0, 0, 0]])
# applying mask to array elements
gfg = geek.ma.compress_cols(arr)
print(gfg)
輸出:
[[1 2] [4 5]]
範例2:
Python3
# importing numpy as geek
import numpy as geek
# defining array
arr = geek.ma.array(geek.arange(9).reshape(3, 3), mask=[
[1, 0, 0], [1, 0, 0], [0, 0, 0]])
# applying mask to array elements
gfg = geek.ma.compress_cols(arr)
print(gfg)
輸出:
[[1 2] [4 5] [7 8]]
相關用法
- Python Wand function()用法及代碼示例
- Python Sorted()用法及代碼示例
- Python Numbers choice()用法及代碼示例
- Python Tkinter askopenfile()用法及代碼示例
- Python ord()用法及代碼示例
- Python round()用法及代碼示例
- Python id()用法及代碼示例
- Python vars()用法及代碼示例
注:本文由純淨天空篩選整理自code_hunt大神的英文原創作品 numpy.ma.compress_cols() function in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。