class_docstr: Equivalent of numpy.ndarray backed by TensorFlow tensors.
  
  This does not support all features of NumPy ndarrays e.g. strides and
  memory order since, unlike NumPy, the backing storage is not a raw memory
  buffer.
  
  TODO(srbs): Clearly specify which attributes and methods are not supported
  or if there are any differences in behavior.
docstr: Initializes an ndarray.
  
  This is a low level interface for building ndarrays and should be avoided.
  Users should instead use methods in array_creation.py.
  
  This class provides a numpy.ndarray like interface for a TF Tensor with a
  fully-defined shape. Note that, unlike the backing buffer of np.ndarray,
  Tensors are immutable. So, operations like `__setitem__` are performed by
  replacing the Tensor. This restricts the ability to implement NumPy `view`
  semantics.
  
  Compared to numpy.ndarray, this does not support `offset`, `strides`
  and `order` arguments.
  
  Args:
    shape: The shape of the array. Must be a scalar, an iterable of integers
      or a `TensorShape` object.
    dtype: Optional. The dtype of the array. Must be a python type, a numpy
      type or a tensorflow `DType` object.
    buffer: Optional. The backing buffer of the array. Must have shape
      `shape`. Must be a `ndarray`, `np.ndarray` or a `Tensor`.
  
  Raises:
    ValueError: If `buffer` is specified and its shape does not match
     `shape`.
docstr_tok: ["Initializes","an","ndarray",".","This","is","a","low","level","interface","for","building","ndarrays","and","should","be","avoided",".","Users","should","instead","use","methods","in","array_creation.py",".","This","class","provides","a","numpy.ndarray","like","interface","for","a","TF","Tensor","with","a","fully-defined","shape",".","Note","that",",","unlike","the","backing","buffer","of","np.ndarray",",","Tensors","are","immutable",".","So",",","operations","like","`","__setitem__","`","are","performed","by","replacing","the","Tensor",".","This","restricts","the","ability","to","implement","NumPy","`","view","`","semantics",".","Compared","to","numpy.ndarray",",","this","does","not","support","`","offset","`",",","`","strides","`","and","`","order","`","arguments",".","Args",":","shape",":","The","shape","of","the","array",".","Must","be","a","scalar",",","an","iterable","of","integers","or","a","`","TensorShape","`","object",".","dtype",":","Optional",".","The","dtype","of","the","array",".","Must","be","a","python","type",",","a","numpy","type","or","a","tensorflow","`","DType","`","object",".","buffer",":","Optional",".","The","backing","buffer","of","the","array",".","Must","have","shape","`","shape","`",".","Must","be","a","`","ndarray","`",",","`","np.ndarray","`","or","a","`","Tensor","`",".","Raises",":","ValueError",":","If","`","buffer","`","is","specified","and","its","shape","does","not","match","`","shape","`","."]
code: def __init__(
      self, shape, dtype=float, buffer=None
  ):  # pylint: disable=redefined-builtin
      """Initializes an ndarray.
  
      This is a low level interface for building ndarrays and should be avoided.
      Users should instead use methods in array_creation.py.
  
      This class provides a numpy.ndarray like interface for a TF Tensor with a
      fully-defined shape. Note that, unlike the backing buffer of np.ndarray,
      Tensors are immutable. So, operations like `__setitem__` are performed by
      replacing the Tensor. This restricts the ability to implement NumPy `view`
      semantics.
  
      Compared to numpy.ndarray, this does not support `offset`, `strides`
      and `order` arguments.
  
      Args:
        shape: The shape of the array. Must be a scalar, an iterable of integers
          or a `TensorShape` object.
        dtype: Optional. The dtype of the array. Must be a python type, a numpy
          type or a tensorflow `DType` object.
        buffer: Optional. The backing buffer of the array. Must have shape
          `shape`. Must be a `ndarray`, `np.ndarray` or a `Tensor`.
  
      Raises:
        ValueError: If `buffer` is specified and its shape does not match
         `shape`.
      """
      if dtype and not isinstance(dtype, tf.DType):
          dtype = tf.as_dtype(np.dtype(dtype))
      if buffer is None:
          buffer = tf.zeros(shape, dtype=dtype)
      else:
          if isinstance(buffer, ndarray):
              buffer = buffer.data
          elif isinstance(buffer, np.ndarray):
              # If `buffer` is a np.ndarray, the Tensor will share the underlying
              # storage of the array.
              buffer = convert_to_tensor(value=buffer, dtype=dtype)
          elif not isinstance(buffer, tf.Tensor):
              raise ValueError(
                  "Unexpected type for `buffer` {}. Must be an ndarray,"
                  " Tensor or np.ndarray.".format(type(buffer))
              )
  
          if (
              shape is not None
              and tuple(shape) != buffer._shape_tuple()
          ):  # pylint: disable=protected-access
              # TODO(srbs): NumPy allows this. Investigate if/how to support this.
              raise ValueError("shape arg must match buffer.shape.")
  
      assert isinstance(buffer, tf.Tensor)
      if dtype and dtype != buffer.dtype:
          buffer = tf.bitcast(buffer, dtype)
      self._data = buffer
      self.base = None
  
imports: import numpy
  import six
  import tensorflow.compat.v2
  from trax.tf_numpy.numpy_impl import dtypes
label_desc: Use image node_id 1 to create a new ndarray object from inherited base classes: object with example: obj = ndarray(shape, dtype, buffer)