I’m sure there are better approaches and you could speed it up more, but you could use index_put_ with the accumulate=True argument instead of the for loop and precompute some indices.
Here is a code snippet:
def fun1():
    result = torch.full(( 32, 256, 256), -1.)
    data = torch.full(( 32, 40000), 1.)
    count = torch.zeros((256,256))
    indices = torch.tensor(([[1,2],[0,0],[1,2],[1,1],[1,0],[0,0],[1,2],[2,2],[2,2],[0,0]]))
    
    for i, indx in enumerate(indices):
            if(count[indx [0], indx [1]] == 0):
                result[:, indx [0], indx [1]] = data [:, i]
            else:
                result[:, indx [0], indx [1]] += data [:, i]
            count[indx [0], indx [1]] += 1
    
    #mask_zero = (count == 0)
    #count[mask_zero] = 1
    #count = torch.Tensor(count)
    #average= result/count
    uidx, ucount = indices.unique(dim=0, return_counts=True)
    result[:, uidx[:, 0], uidx[:, 1]] /= ucount
    return result#average


def fun2():
    result2 = torch.full((32, 256, 256), -1.)
    data = torch.full((32, 40000), 1.)
    indices = torch.tensor([[1,2],[0,0],[1,2],[1,1],[1,0],[0,0],[1,2],[2,2],[2,2],[0,0]])
    
    # prime result2
    result2[:, indices[:, 0], indices[:, 1]] = 0
    
    # precompute fast_idx
    fast_idx = torch.arange(32).unsqueeze(1).expand(-1, 10).transpose(1, 0).reshape(-1)
    
    result2.index_put_(
        (fast_idx,
         indices[:, 0].unsqueeze(1).expand(-1, 32).reshape(-1),
         indices[:, 1].unsqueeze(1).expand(-1, 32).reshape(-1)),
        data[fast_idx, torch.arange(10).unsqueeze(1).expand(-1, 32).reshape(-1)],
        accumulate=True)
    
    uidx, ucount = indices.unique(dim=0, return_counts=True)
    result2[:, uidx[:, 0], uidx[:, 1]] /= ucount
    return result2

avg1 = fun1()
avg2 = fun2()
print((avg1 - avg2).abs().max())
> tensor(0.)

%timeit fun1()
> 6.32 ms ± 754 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

%timeit fun2()
> 5.75 ms ± 134 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

which could potentially speed up your method.
Note that I removed the slower count calculation from your code and replaced it with the unique method, which yields a speedup on my setup.