Ejemplo n.º 1
0
def reshape(a, newshape):
    """Reshapes an array.

  Args:
    a: array_like. Could be an ndarray, a Tensor or any object that can
      be converted to a Tensor using `tf.convert_to_tensor`.
    newshape: 0-d or 1-d array_like.

  Returns:
    An ndarray with the contents and dtype of `a` and shape `newshape`.
  """
    a = array_creation.asarray(a)
    if isinstance(newshape, arrays.ndarray):
        newshape = utils.get_shape_from_ndarray(newshape)
    return utils.tensor_to_ndarray(tf.reshape(a.data, newshape))
Ejemplo n.º 2
0
def zeros(shape, dtype=float):
    """Returns an ndarray with the given shape and type filled with zeros.

  Args:
    shape: A fully defined shape. Could be
      - NumPy array or a python scalar, list or tuple of integers,
      - TensorFlow tensor/ndarray of integer type and rank <=1.
    dtype: Optional, defaults to float. The type of the resulting ndarray.
      Could be a python type, a NumPy type or a TensorFlow `DType`.

  Returns:
    An ndarray.
  """
    if dtype:
        dtype = utils.to_tf_type(dtype)
    if isinstance(shape, arrays.ndarray):
        shape = utils.get_shape_from_ndarray(shape)
    return utils.tensor_to_ndarray(tf.zeros(shape, dtype=dtype))