meshgrid

paddle.fluid.layers.meshgrid(input, name=None)[source]

This op takes a list of N tensors as input, each of which is 1-dimensional vector, and creates N-dimensional grids.

Parameters
  • input (Variable) – tensors (list of tensor): the shapes of input k tensors are (N1,), (N2,),…, (Nk,). Support data types: float64, float32, int32, int64.

  • name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name.

Returns

k tensors. The shape of each tensor is (N1, N2, …, Nk)

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.meshgrid, line 16)

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

.. code-block:: python
    import paddle
    import paddle.fluid as fluid
    import numpy as np
    x = fluid.data(name='x', shape=[100], dtype='int32')
    y = fluid.data(name='y', shape=[200], dtype='int32')
    input_1 = np.random.randint(0, 100, [100, ]).astype('int32')
    input_2 = np.random.randint(0, 100, [200, ]).astype('int32')
    exe = fluid.Executor(place=fluid.CPUPlace())
    grid_x, grid_y = fluid.layers.meshgrid([x, y])
    res_1, res_2 = exe.run(fluid.default_main_program(),
                           feed={'x': input_1,
                                 'y': input_2},
                           fetch_list=[grid_x, grid_y])

    #the shape of res_1 is (100, 200)
    #the shape of res_2 is (100, 200)

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

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

.. code-block:: python
    #example 2: in dygraph mode
    import paddle
    import paddle.fluid as fluid
    import numpy as np
    input_3 = np.random.randint(0, 100, [100, ]).astype('int32')
    input_4 = np.random.randint(0, 100, [200, ]).astype('int32')
    with fluid.dygraph.guard():
        tensor_3 = fluid.dygraph.to_variable(input_3)
        tensor_4 = fluid.dygraph.to_variable(input_4)
        grid_x, grid_y = fluid.layers.meshgrid([tensor_3, tensor_4])
    #the shape of grid_x is (100, 200)
    #the shape of grid_y is (100, 200)