Python Pytorch:有界形状的坐标列表

Python Pytorch:有界形状的坐标列表,python,pytorch,tensor,Python,Pytorch,Tensor,假设我有一个PyTorch张量,表示1000个坐标的列表,其中索引0-2是独立的x-y-z坐标,索引3是与坐标相关联的值 我想生成这些坐标的“图形”:一个I x J x K网格,每个索引处的坐标值 例如: batch_size=10 channels = 2 n_coords = 1000 len_coords = 4 low = 0 high=10 some_limit = 5 coords = torch.zeros(batch_size, channels, n_coords, len

假设我有一个PyTorch张量,表示1000个坐标的列表,其中索引0-2是独立的x-y-z坐标,索引3是与坐标相关联的值

我想生成这些坐标的“图形”:一个I x J x K网格,每个索引处的坐标值

例如:

batch_size=10
channels = 2
n_coords = 1000

len_coords = 4
low = 0
high=10
some_limit = 5

coords = torch.zeros(batch_size, channels, n_coords, len_coords).random_(low, high) # a set of coordinates
#SOME OPERATION YIELDS ->
image = torch.zeros(batch_size, channels, high, high, high) #The 'space' I want to embed the coo-ordinates in
我有一个解决方案,涉及我开发的循环,可以产生预期的结果:

coords_shape = torch.Tensor([*data.shape][0:2]).int()
axis_shape = torch.Tensor([high,high,high]).int()    
image_shape = torch.cat((coords_shape, axis_shape), axis=0)
image = torch.zeros(*image_shape)


for b in range(coords.shape[0]):
    for c in range(coords.shape[1]):
        for v in range(coords.shape[2]):
                elem = coords[b, c, v]
                if(elem[3]>some_limit):
                    image[batch_elem, channel, int(elem[0]), int(elem[1]), int(elem[2])]=elem[3]
我知道这是次优,因为循环


有没有一种更聪明的方法来实现这一点?

如果你能开发出一种结合的方法,那么可能。如果你能开发出一种结合的方法,那么可能。