replacement of nditer for numpy array for pytorch tensor
I am looking for similar functionality for pytorch tensor as of nditer of numpy array, see this link with a small example. 
https://discuss.pytorch.org/t/replacement-of-np-nditer-for-torch/64024?u=songqsh

I agree with comments that iterating element by element is reraly a good idea for interaction with arrays or tensors. nditer has lots of functionality, here is just an iteration through all elements in the tensor which returns coordinates of the element together with element itself: 

def deep_iter(data, ix=tuple()):
    try:
        for i, element in enumerate(data):
            yield from deep_iter(element, ix + (i,))
    except:
        yield ix, data


So for example at pytorch forum it can be used as following:

new_values = {}
for i, value in deep_iter(a):
    if all(map(lambda x: 0 &lt; x &lt; (a.shape[1] - 1), i)):
        new_values[i] = calc_average(i, a) #write func to calc average

for i, new_value in new_values.items():
    a[i] = new_value

