How can I sum elements of a tensor based on a condition of one out of two values in its index pair into a new tensor using the pytorch package?
Given the following index tensor: id = ([[0, 1], [0, 2], [1,2]]) that corresponds to the tensor: val = ([[a, b, c], [e, f, g], [h, i, j]]) such that element [a, b, c] has an index of [0,1], element [e, f, g] has an index of [0, 2], ectara. How can I return a tensor where in index representation it is new_ten_id = ([[[0, 1] + [0, 2]], [[1, 2] + (-[0, 1])], [(-[0, 2]) + (-[1, 2])]]) and the tensor of values would be new_ten_val = ([[a+e, b+f, c+g], [h-a, i-b, j-c], [-e-h, -f-i, -g-j]]). ----- I have tried the following code: n_part = 3 F_sum_empty = torch.zeros(n_part, 3) F_sum = torch.scatter_a
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.