I have a series of measurements made over a 2D space. The measurements come as [x, y] and M where x,y are the coordinates of where the measurement was made and M is the result of the measurement. I want to use these measurements to update a 2D grid of values, let’s say dim [11,11], that represents my knowledge of the underlying function on a 1 meter grid. The 2D grid can be considered a discretized basis the underlying function.

The x and y of each measurement are not discretized with each of x and y ranging from 0 to 10. I would like to convert each incoming measurement into a dim [11,11] tensor where the value of the tensor is zero everywhere except in the vicinity of x,y. For example:

If x,y were 0,0 I want the [1,1] location of the tensor to be M.

If x,y were 0.5,0.5, I want locations [1,1], [1,2], [2,1] and [2,2] to each be M/4 etc.

If x,y were 10,10, I want location [11,11] to be M

Based on your description it seems your use case is a linear interpolation.

Could you post a dummy input tensor with an example tensor containing the indices, please?

Yes, it is interpolation, but just over a few locations.

Here’s an example for the case where x,y is 0,1 and the measurement is 3.4.

I’ve showing it implemented using sparse tensors. How do I generalize it to the case where the x,y values are not integers?

location = torch.LongTensor([[1],[2]])

measurement = torch.FloatTensor([3.4])

torch.sparse.FloatTensor(location,measurement, torch.Size([11,11])).to_dense()

tensor([[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,

0.0000, 0.0000],

[0.0000, 0.0000, 3.4000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,

0.0000, 0.0000],

[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,

0.0000, 0.0000],

[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,

0.0000, 0.0000],

[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,

0.0000, 0.0000],

[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,

0.0000, 0.0000],

[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,

0.0000, 0.0000],

[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,

0.0000, 0.0000],

[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,

0.0000, 0.0000],

[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,

0.0000, 0.0000],

[0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000,

0.0000, 0.0000]])