numpy.MaskedArray.compressed() 函数将所有非屏蔽数据作为一维数组返回。
用法: numpy.MaskedArray.compressed(self)
返回:[ndarray] 返回一个包含非屏蔽数据的新 ndarray。
代码1:
# Python program explaining
# numpy.MaskedArray.compressed() 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(10), mask =[0]*6 + [1]*4)
gfg = arr.compressed()
print(gfg)
输出:
[0 1 2 3 4 5]
代码2:
# Python program explaining
# numpy.MaskedArray.compressed() 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(7), mask =[0]*4 + [1]*3)
gfg = arr.compressed()
print(gfg)
输出:
[0 1 2 3]
相关用法
- Python Numpy numpy.resize()用法及代码示例
- Python Numpy numpy.transpose()用法及代码示例
- Python Numpy numpy.ndarray.__lt__()用法及代码示例
- Python Numpy numpy.ndarray.__gt__()用法及代码示例
- Python Numpy numpy.ndarray.__le__()用法及代码示例
- Python Numpy numpy.ndarray.__ge__()用法及代码示例
- Python Numpy numpy.ndarray.__eq__()用法及代码示例
- Python Numpy numpy.ndarray.__ne__()用法及代码示例
- Python Numpy numpy.ndarray.__neg__()用法及代码示例
- Python Numpy numpy.ndarray.__pos__()用法及代码示例
- Python Numpy numpy.ndarray.__truediv__()用法及代码示例
- Python Numpy numpy.ndarray.__mul__()用法及代码示例
- Python Numpy numpy.ndarray.__sub__()用法及代码示例
- Python Numpy numpy.ndarray.__add__()用法及代码示例
- Python Numpy numpy.ndarray.__floordiv__()用法及代码示例
- Python Numpy numpy.ndarray.__mod__()用法及代码示例
- Python Numpy numpy.ndarray.__invert__()用法及代码示例
- Python Numpy numpy.ndarray.__divmod__()用法及代码示例
- Python Numpy numpy.ndarray.__pow__()用法及代码示例
- Python Numpy numpy.ndarray.__rshift__()用法及代码示例
- Python Numpy numpy.ndarray.__lshift__()用法及代码示例
- Python Numpy numpy.ndarray.__isub__()用法及代码示例
- Python Numpy numpy.ndarray.__iadd__()用法及代码示例
- Python Numpy numpy.ndarray.__xor__()用法及代码示例
注:本文由纯净天空筛选整理自sanjoy_62大神的英文原创作品 Numpy MaskedArray.compressed() function – Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。