View a slice or the entirety of an ndarray.

  Args:
    array: The input array, as an numpy.ndarray.
    slicing: Optional slicing string, e.g., "[:, 1:3, :]".
    mapping: Optional mapping string. Supported mappings:
      `None` or case-insensitive `'None'`: Unmapped nested list.
      `'image/png'`: Image encoding of a 2D sliced array or 3D sliced array
        with 3 as the last dimension. If the sliced array is not 2D or 3D with
        3 as the last dimension, a `ValueError` will be thrown.
      `health-pill`: A succinct summary of the numeric values of a tensor.
        See documentation in [`health_pill_calc.py`] for more details.

  Returns:
    1. dtype as a `str`.
    2. shape of the sliced array, as a tuple of `int`s.
    3. the potentially sliced values, as a nested `list`.

def array_view(array, slicing=None, mapping=None):
  """View a slice or the entirety of an ndarray.

  Args:
    array: The input array, as an numpy.ndarray.
    slicing: Optional slicing string, e.g., "[:, 1:3, :]".
    mapping: Optional mapping string. Supported mappings:
      `None` or case-insensitive `'None'`: Unmapped nested list.
      `'image/png'`: Image encoding of a 2D sliced array or 3D sliced array
        with 3 as the last dimension. If the sliced array is not 2D or 3D with
        3 as the last dimension, a `ValueError` will be thrown.
      `health-pill`: A succinct summary of the numeric values of a tensor.
        See documentation in [`health_pill_calc.py`] for more details.

  Returns:
    1. dtype as a `str`.
    2. shape of the sliced array, as a tuple of `int`s.
    3. the potentially sliced values, as a nested `list`.
  """

  dtype = translate_dtype(array.dtype)
  sliced_array = (array[command_parser._parse_slices(slicing)] if slicing
                  else array)

  if np.isscalar(sliced_array) and str(dtype) == 'string':
    # When a string Tensor (for which dtype is 'object') is sliced down to only
    # one element, it becomes a string, instead of an numpy array.
    # We preserve the dimensionality of original array in the returned shape
    # and slice.
    ndims = len(array.shape)
    slice_shape = []
    for _ in range(ndims):
      sliced_array = [sliced_array]
      slice_shape.append(1)
    return dtype, tuple(slice_shape), sliced_array
  else:
    shape = sliced_array.shape
    if mapping == "image/png":
      if len(sliced_array.shape) == 2:
        return dtype, shape, array_to_base64_png(sliced_array)
      elif len(sliced_array.shape) == 3:
        raise NotImplementedError(
            "image/png mapping for 3D array has not been implemented")
      else:
        raise ValueError("Invalid rank for image/png mapping: %d" %
                         len(sliced_array.shape))
    elif mapping == 'health-pill':
      health_pill = health_pill_calc.calc_health_pill(array)
      return dtype, shape, health_pill
    elif mapping is None or mapping == '' or  mapping.lower() == 'none':
      return dtype, shape, sliced_array.tolist()
    else:
      raise ValueError("Invalid mapping: %s" % mapping)