📅  最后修改于: 2022-03-11 14:45:07.990000             🧑  作者: Mango
import numpy
data = numpy.array([[ 1, 2, 5 ]])
mask = numpy.array([[0,1,0]])
numpy.ma.masked_array(data, ~mask)
# note this probably won't work right for non-boolean (T/F) values
# or
numpy.ma.masked_array(data, numpy.logical_not(mask))
# for example
>>> a = numpy.array([False,True,False])
>>> ~a
array([ True, False, True], dtype=bool)
>>> numpy.logical_not(a)
array([ True, False, True], dtype=bool)
>>> a = numpy.array([0,1,0])
>>> ~a
array([-1, -2, -1])
>>> numpy.logical_not(a)
array([ True, False, True], dtype=bool)