torch.meshgrid函数

torch.meshgrid函数

其作用是对于给定的x,y坐标,返回(x,y)所组合形成的所有点的横,纵坐标

比如下文中x.shape=10
m_x.shape=(10,10)

测试代码如下:

import torch
x=torch.arange(0,10)
y=torch.arange(50,60)
m_x,m_y=torch.meshgrid(x,y)
print(m_x,m_y)
>>>tensor([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
        [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
        [3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
        [4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
        [5, 5, 5, 5, 5, 5, 5, 5, 5, 5],
        [6, 6, 6, 6, 6, 6, 6, 6, 6, 6],
        [7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
        [8, 8, 8, 8, 8, 8, 8, 8, 8, 8],
        [9, 9, 9, 9, 9, 9, 9, 9, 9, 9]]) tensor([[50, 51, 52, 53, 54, 55, 56, 57, 58, 59],
        [50, 51, 52, 53, 54, 55, 56, 57, 58, 59],
        [50, 51, 52, 53, 54, 55, 56, 57, 58, 59],
        [50, 51, 52, 53, 54, 55, 56, 57, 58, 59],
        [50, 51, 52, 53, 54, 55, 56, 57, 58, 59],
        [50, 51, 52, 53, 54, 55, 56, 57, 58, 59],
        [50, 51, 52, 53, 54, 55, 56, 57, 58, 59],
        [50, 51, 52, 53, 54, 55, 56, 57, 58, 59],
        [50, 51, 52, 53, 54, 55, 56, 57, 58, 59],
        [50, 51, 52, 53, 54, 55, 56, 57, 58, 59]])

猜你喜欢

转载自blog.csdn.net/fei_YuHuo/article/details/117751049