meshgrid

paddle.tensor.meshgrid(input, name=None)

该OP的输入是tensor list, 包含 k 个一维Tensor,对每个Tensor做扩充操作,输出 k 个 k 维tensor。

参数

  • input (Variable)- 输入变量为 k 个一维Tensor,形状分别为(N1,), (N2,), …, (Nk, )。支持数据类型为float32,float64,int32,int64。
  • name (str, 可选)- 具体用法请参见 Name ,一般无需设置,默认值为None。

返回

k 个 k 维Tensor,每个Tensor的形状均为(N1, N2, …, Nk)。

返回类型

变量(Variable)

代码示例

  1. #静态图示例
  2. import paddle
  3. import paddle.fluid as fluid
  4. import numpy as np
  5. x = fluid.data(name='x', shape=[100], dtype='int32')
  6. y = fluid.data(name='y', shape=[200], dtype='int32')
  7. input_1 = np.random.randint(0, 100, [100, ]).astype('int32')
  8. input_2 = np.random.randint(0, 100, [200, ]).astype('int32')
  9. exe = fluid.Executor(place=fluid.CPUPlace())
  10. grid_x, grid_y = paddle.tensor.meshgrid([x, y])
  11. res_1, res_2 = exe.run(fluid.default_main_program(),
  12. feed={'x': input_1,
  13. 'y': input_2},
  14. fetch_list=[grid_x, grid_y])
  15. #the shape of res_1 is (100, 200)
  16. #the shape of res_2 is (100, 200)
  1. #动态图示例
  2. import paddle
  3. import paddle.fluid as fluid
  4. import numpy as np
  5. input_3 = np.random.randint(0, 100, [100, ]).astype('int32')
  6. input_4 = np.random.randint(0, 100, [200, ]).astype('int32')
  7. with fluid.dygraph.guard():
  8. tensor_3 = fluid.dygraph.to_variable(input_3)
  9. tensor_4 = fluid.dygraph.to_variable(input_4)
  10. grid_x, grid_y = paddle.tensor.meshgrid([tensor_3, tensor_4])
  11. #the shape of grid_x is (100, 200)
  12. #the shape of grid_y is (100, 200)