reshape

dragon.vm.tensorflow.reshape(
  tensor,
  shape,
  name=None
)[source]

Change the dimensions of input.

Examples:

# Provide a determined value for each dimension if possible
x = tf.ones(shape=(1, 2, 3, 4))
print(tf.reshape(x, shape=[6, 4]).shape)  # [6, 4]

# Set the existing dimensions to ``0`` if it unchanged
print(tf.reshape(x, shape=[0, 0, 12]).shape)  # [1, 2, 12]
print(tf.reshape(x, shape=[0, 0, 0, 0]).shape)  # [1, 2, 3, 4]
print(tf.reshape(x, shape=[0, 0, 0, 0, 0]).shape)  # Wrong

# You can also set ``-1`` once to infer the value
print(tf.reshape(x, shape=[-1, 4]).shape)  # [6, 4]
print(tf.reshape(x, shape=[-1, -1]).shape)  # Wrong
Parameters:
  • tensor (dragon.Tensor) – The input tensor.
  • shape (Union[Sequence[int], dragon.Tensor]) – The output shape.
  • name (str, optional) – The operation name.