numpy.ma.where

ma.where(condition, x=<no value>, y=<no value>)[源代码]

返回包含元素的屏蔽数组 xy ,视情况而定。

注解

只有时 condition 提供,此函数与 nonzero . 本文档的其余部分仅涵盖提供了所有三个参数的情况。

参数
condition列阵,布尔

如果是真的,屈服 x ,否则屈服 y .

x, y阵列式,可选

要从中选择的值。 xycondition 需要能够以某种形式广播。

返回
outMaskedArray

带有 masked 条件被屏蔽的元素,来自的元素 x 在哪里? condition 是真的,元素来自 y 别处。

参见

numpy.where

顶层numpy模块中的等效函数。

nonzero

省略x和y时调用的函数

实例

>>> x = np.ma.array(np.arange(9.).reshape(3, 3), mask=[[0, 1, 0],
...                                                    [1, 0, 1],
...                                                    [0, 1, 0]])
>>> x
masked_array(
  data=[[0.0, --, 2.0],
        [--, 4.0, --],
        [6.0, --, 8.0]],
  mask=[[False,  True, False],
        [ True, False,  True],
        [False,  True, False]],
  fill_value=1e+20)
>>> np.ma.where(x > 5, x, -3.1416)
masked_array(
  data=[[-3.1416, --, -3.1416],
        [--, -3.1416, --],
        [6.0, --, 8.0]],
  mask=[[False,  True, False],
        [ True, False,  True],
        [False,  True, False]],
  fill_value=1e+20)