code: def where(condition, x=None, y=None):
      """
      Return elements, either from `x` or `y`, depending on `condition`.
  
      If only `condition` is given, return ``condition.nonzero()``.
  
      Parameters
      ----------
      condition : array_like, bool
          When 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 : Tensor or tuple of Tensors
          If both `x` and `y` are specified, the output tensor contains
          elements of `x` where `condition` is True, and elements from
          `y` elsewhere.
  
          If only `condition` is given, return the tuple
          ``condition.nonzero()``, the indices where `condition` is True.
  
      See Also
      --------
      nonzero, choose
  
      Notes
      -----
      If `x` and `y` are given and input arrays are 1-D, `where` is
      equivalent to::
  
          [xv if c else yv for (c,xv,yv) in zip(condition,x,y)]
  
      Examples
      --------
      >>> import mars.tensor as mt
  
      >>> mt.where([[True, False], [True, True]],
      ...          [[1, 2], [3, 4]],
      ...          [[9, 8], [7, 6]]).execute()
      array([[1, 8],
             [3, 4]])
  
      >>> mt.where([[0, 1], [1, 0]]).execute()
      (array([0, 1]), array([1, 0]))
  
      >>> x = mt.arange(9.).reshape(3, 3)
      >>> mt.where( x > 5 ).execute()
      (array([2, 2, 2]), array([0, 1, 2]))
      >>> mt.where(x < 5, x, -1).execute()               # Note: broadcasting.
      array([[ 0.,  1.,  2.],
             [ 3.,  4., -1.],
             [-1., -1., -1.]])
  
      Find the indices of elements of `x` that are in `goodvalues`.
  
      >>> goodvalues = [3, 4, 7]
      >>> ix = mt.isin(x, goodvalues)
      >>> ix.execute()
      array([[False, False, False],
             [ True,  True, False],
             [False,  True, False]])
      >>> mt.where(ix).execute()
      (array([1, 1, 2]), array([0, 1, 1]))
      """
      if (x is None) != (y is None):
          raise ValueError(
              "either both or neither of x and y should be given"
          )
  
      if x is None and y is None:
          return astensor(condition).nonzero()
  
      x, y = astensor(x), astensor(y)
      dtype = np.result_type(x.dtype, y.dtype)
      shape = broadcast_shape(x.shape, y.shape)
  
      if np.isscalar(condition):
          return broadcast_to(x if condition else y, shape).astype(
              dtype
          )
      else:
          condition = astensor(condition)
          op = TensorWhere(dtype=dtype)
          return op(condition, x, y, shape=shape)
  
imports: import itertools
  import numpy
  from ...None import opcodes
  from ...serialization.serializables import KeyField
  from ...utils import has_unknown_shape
  from ..utils import broadcast_shape, unify_chunks
  from ..array_utils import as_same_device, device
  from ..core import TENSOR_TYPE
  from ..operands import TensorOperand, TensorOperandMixin
  from ..datasource import tensor
  from .broadcast_to import broadcast_to
label_desc: Use image node_id 1 for calling a global function with example usage: where(condition, x, y) and returns: astensor, broadcast_to, op