Solved by KFrank in post #2 
              
              
                Hi Marc! 

This is really a python issue – not specific to pytorch. 
range = max - min

This line (when uncommented) sets range to (refer to) 
max - min, which, in this case, is a pytorch tensor. 
Then when you try to execute 
for j in range(16):

range no longer refers to the built-in python “range…