📜  Python中的 numpy.ma.compress_cols()函数

📅  最后修改于: 2022-05-13 01:54:53.279000             🧑  作者: Mango

Python中的 numpy.ma.compress_cols()函数

先决条件: numpy

这个 numpy 内置函数抑制在二维数组中包含屏蔽值的整列。

下面是上述函数的实现。

示例 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)


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]]

示例 2:

蟒蛇3

# 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]]