parameters: (condition, x=_NoValue, y=_NoValue)
return_statement: return masked_array(data, mask=mask)
docstring: Return a masked array with elements from `x` or `y`, depending on condition.
  
      .. note::
          When only `condition` is provided, this function is identical to
          `nonzero`. The rest of this documentation covers only the case where
          all three arguments are provided.
  
      Parameters
      ----------
      condition : array_like, bool
          Where True, yield `x`, otherwise yield `y`.
      x, y : array_like, optional
          Values from which to choose. `x`, `y` and `condition` need to be
          broadcastable to some shape.
  
      Returns
      -------
      out : MaskedArray
          An masked array with `masked` elements where the condition is masked,
          elements from `x` where `condition` is True, and elements from `y`
          elsewhere.
  
      See Also
      --------
      numpy.where : Equivalent function in the top-level NumPy module.
      nonzero : The function that is called when x and y are omitted
  
      Examples
      --------
      >>> 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)
docstring_summary: Return a masked array with elements from `x` or `y`, depending on condition.
docstring_tokens: Return a masked array with elements from x or y depending on condition .
function: def where(condition, x=_NoValue, y=_NoValue):
      """
      Return a masked array with elements from `x` or `y`, depending on condition.
  
      .. note::
          When only `condition` is provided, this function is identical to
          `nonzero`. The rest of this documentation covers only the case where
          all three arguments are provided.
  
      Parameters
      ----------
      condition : array_like, bool
          Where True, yield `x`, otherwise yield `y`.
      x, y : array_like, optional
          Values from which to choose. `x`, `y` and `condition` need to be
          broadcastable to some shape.
  
      Returns
      -------
      out : MaskedArray
          An masked array with `masked` elements where the condition is masked,
          elements from `x` where `condition` is True, and elements from `y`
          elsewhere.
  
      See Also
      --------
      numpy.where : Equivalent function in the top-level NumPy module.
      nonzero : The function that is called when x and y are omitted
  
      Examples
      --------
      >>> 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)
  
      """
  
      # handle the single-argument case
      missing = (x is _NoValue, y is _NoValue).count(True)
      if missing == 1:
          raise ValueError("Must provide both 'x' and 'y' or neither.")
      if missing == 2:
          return nonzero(condition)
  
      # we only care if the condition is true - false or masked pick y
      cf = filled(condition, False)
      xd = getdata(x)
      yd = getdata(y)
  
      # we need the full arrays here for correct final dimensions
      cm = getmaskarray(condition)
      xm = getmaskarray(x)
      ym = getmaskarray(y)
  
      # deal with the fact that masked.dtype == float64, but we don't actually
      # want to treat it as that.
      if x is masked and y is not masked:
          xd = np.zeros((), dtype=yd.dtype)
          xm = np.ones((),  dtype=ym.dtype)
      elif y is masked and x is not masked:
          yd = np.zeros((), dtype=xd.dtype)
          ym = np.ones((),  dtype=xm.dtype)
  
      data = np.where(cf, xd, yd)
      mask = np.where(cf, xm, ym)
      mask = np.where(cm, np.ones((), dtype=mask.dtype), mask)
  
      # collapse the mask, for backwards compatibility
      mask = _shrink_mask(mask)
  
      return masked_array(data, mask=mask)
function_tokens: def where ( condition , x = _NoValue , y = _NoValue ) : # handle the single-argument case missing = ( x is _NoValue , y is _NoValue ) . count ( True ) if missing == 1 : raise ValueError ( "Must provide both 'x' and 'y' or neither." ) if missing == 2 : return nonzero ( condition ) # we only care if the condition is true - false or masked pick y cf = filled ( condition , False ) xd = getdata ( x ) yd = getdata ( y ) # we need the full arrays here for correct final dimensions cm = getmaskarray ( condition ) xm = getmaskarray ( x ) ym = getmaskarray ( y ) # deal with the fact that masked.dtype == float64, but we don't actually # want to treat it as that. if x is masked and y is not masked : xd = np . zeros ( ( ) , dtype = yd . dtype ) xm = np . ones ( ( ) , dtype = ym . dtype ) elif y is masked and x is not masked : yd = np . zeros ( ( ) , dtype = xd . dtype ) ym = np . ones ( ( ) , dtype = xm . dtype ) data = np . where ( cf , xd , yd ) mask = np . where ( cf , xm , ym ) mask = np . where ( cm , np . ones ( ( ) , dtype = mask . dtype ) , mask ) # collapse the mask, for backwards compatibility mask = _shrink_mask ( mask ) return masked_array ( data , mask = mask )