cross

paddle.fluid.layers.cross(input, other, dim=None)[source]

Returns the cross product of vectors in dimension dim of the input and other tensor. Inputs must have the same shape, and the size of their dim-th dimension should be equla to 3. If dim is not given, it defaults to the first dimension found with the size 3.

Parameters
  • input (Variable) – The first input tensor variable.

  • other (Variable) – The second input tensor variable.

  • dim (int) – The dimension to take the cross-product in.

Returns

A Tensor with same data type as input.

Return type

Variable

Examples

System Message: ERROR/3 (/usr/local/lib/python2.7/dist-packages/paddle/fluid/layers/nn.py:docstring of paddle.fluid.layers.cross, line 17)

Error in “code-block” directive: maximum 1 argument(s) allowed, 11 supplied.

.. code-block:: python
    import paddle
    import paddle.fluid as fluid
    import numpy as np

    data_x = np.array([[1.0, 1.0, 1.0],
                       [2.0, 2.0, 2.0],
                       [3.0, 3.0, 3.0]])
    data_y = np.array([[1.0, 1.0, 1.0],
                       [1.0, 1.0, 1.0],
                       [1.0, 1.0, 1.0]])

    with fluid.dygraph.guard():
        x = fluid.dygraph.to_variable(data_x)
        y = fluid.dygraph.to_variable(data_y)
        out_z1 = fluid.layers.cross(x, y)
        print(out_z1.numpy())
        #[[-1. -1. -1.]
        # [ 2.  2.  2.]
        # [-1. -1. -1.]]
        out_z2 = fluid.layers.cross(x, y, dim=1)
        print(out_z2.numpy())
        #[[0. 0. 0.]
        # [0. 0. 0.]
        # [0. 0. 0.]]