Solved by ptrblck in post #6 
              
              
                Thanks for the code. 
This should work: 
AA = AA.view(A.size(0), -1)
AA -= AA.min(1, keepdim=True)[0]
AA /= AA.max(1, keepdim=True)[0]
AA = AA.view(batch_size, height, width)