reshape

Graph.reshape(tensor, shape, *, name=None)

Reshape a tensor into a new shape, keeping the order of its elements.

Parameters

  • tensor (np.ndarray or Tensor) – The tensor you want to reshape.
  • shape (tuple [ int , ... ]) – The new shape of the tensor. One and only one of the dimensions can be set to -1. In that case, the method will automatically calculate that dimension’s size by keeping the total size constant.
  • name (str or None , optional) – The name of the node.

Returns

The reshaped tensor.

Return type

Tensor

Examples

>>> graph.reshape(tensor=np.ones((4, 4)), shape=(2, 8), name='reshape')
<Tensor: name="reshape", operation_name="reshape", shape=(2, 8)>
>>> graph.reshape(tensor=np.ones((4, 4)), shape=(2, -1), name='reshape_1')
<Tensor: name="reshape_1", operation_name="reshape", shape=(2, 8)>
>>> graph.reshape(tensor=np.ones((4, 4)), shape=(2, -1, 2), name='reshape_2')
<Tensor: name="reshape_2", operation_name="reshape", shape=(2, 4, 2)>
>>> graph.reshape(tensor=np.ones((2, 2)), shape=(-1,), name='reshape_3')
<Tensor: name="reshape_3", operation_name="reshape", shape=(4,)>

Was this useful?