reverse

Graph.reverse(tensor, axis, *, name=None)

Reverse a tensor along some specified dimensions.

Parameters
  • tensor (np.ndarray or Tensor) – The tensor that you want to reverse.

  • axis (list[int]) – The dimensions along which you want to reverse the tensor.

  • name (str, optional) – The name of the node.

Returns

The reversed tensor.

Return type

Tensor

Examples

>>> x = np.array([[1, 2, 3], [4, 5, 6]])

Reverse an array along its first dimension.

>>> graph.reverse(x, [0], name="a")
<Tensor: name="a", operation_name="reverse", shape=(2, 3)>
>>> result = qctrl.functions.calculate_graph(graph=graph, output_node_names=["a"])
>>> result.output["a"]["value"]
array([[4, 5, 6],
       [1, 2, 3]])

Reverse an array along its first and second dimension.

>>> graph.reverse(x, [0, 1], name="b")
<Tensor: name="b", operation_name="reverse", shape=(2, 3)>
>>> result = qctrl.functions.calculate_graph(graph=graph, output_node_names=["b"])
>>> result.output["b"]["value"]
array([[6, 5, 4],
       [3, 2, 1]])