Make Linear Interpolation Grid

Hello, I am trying to create an array a with shape [T, T, T, 3], with T = 2 or 3

array[T - 1, 0, 0] = RGB color A
array[0, T - 1, 0] = RGB color B
array[0, 0, T - 1] = RGB color C

with other elements to be the linear combinations of A, B, C.

array[0, 0, 0] is 0
array[T - 1, T - 1, T - 1] = A + B + C
array[T / 3, T / 3, T / 3] = A / 3 + B / 3 + C / 3 (with T = 3)
array[T / 2, T / 2, 0] = A / 2 + B / 2 (with T = 2)
etc.

Now I suspect what I want to do can be done with torch.meshgrid(T,T), however, I don’t seem to be able to do it.
Any help will be appreciated!

I’m not sure to understand your use case properly, but it seems to me you would like to assign some linear compinations to your tensor.
Wouldn’t this work?

T = 2
x = torch.randn(T, T, T, 3)
x[0, 0, 0] = 0.
x[1, 1, 1] = x[1, 0, 0] + x[0, 1, 0] + x[0, 0, 1]
...
1 Like