def isscalar(val):
  """Returns whether `val` is a scalar value or scalar Tensor."""
  if isinstance(val, (np.ndarray, arrays.ndarray, tf.Tensor)):
    return len(val.shape) == 0  # pylint: disable=g-explicit-length-test
  return np.isscalar(val)
Returns whether `val` is a scalar value or scalar Tensor.
trax/tf_numpy/numpy_impl/utils.py