Assign the new value to a tensor at specific indices
This is a simple example. 

Assume that I have an input tensor M. Now I have a tensor of indices of M with size 2 x 3 such as [[0, 1], [2,2], [0,1]] and a new array of values which is corresponding with the index tensor is [1, 2, 3]. I want to assign these values to the input M satisfying that the value is assigned to the element of M at index [0,1] will be the min value (1 in this example).

It means M[0,1] = 1 and M[2,2] = 2.

Can I do that by using some available functions in Pytorch without a loop?

It can be done without loops, but I am generally not sure whether it is such a great idea, due to significantly increased runtime.

The basic idea is relatively simple: Since tensor assignments always assign the last element, it is sufficient to sort your tuples in M in descending order, according to the respective values stored in the value list (let's call it v).

To do this in pytorch, let us consider the following example:

import torch as t
X = t.randn([3, 3])  # Random matrix of size 3x3
v = t.tensor([1, 2, 3])
M = t.tensor([[0, 2, 0],
              [1, 2, 1]])  # accessing the elements described above

# Showcase pytorch's result with "naive" tensor assignment:
X[tuple(M)] = v  # This would assign the value 3 to position (0, 1)

# To correct behavior, sort v in decreasing order.
v_desc = v.sort(decreasing=True)
# v now contains both the values and the indices of original position
print(v_desc)
# torch.return_types.sort(
#       values=tensor([3, 2, 1]),
#       indices=tensor([2, 1, 0]))


# Access M in the correct order:
M_desc = M[:, v_desc.indices]

# Finally assign correct order:
X[tuple(M_desc)] = v_desc


Again, this is relatively complicated, because it involves sorting the values, and "re-shuffling" of the tensors. You can surely save at least some memory if you perform operations in-place, which is something I disregarded for the sake of legibility.

As an answer whether this can also be achieved without sorting, I am fairly certain that the answer will be "no"; tensor assignments could only be done on fairly simple conditionals, but not something more complicated like your inter-dependent conditionals would require.
