先决条件: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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。