I don’t really know the formula but it basically works the following way:
Assume that the number of elements of A and B are the same.
so what id does is iterating through the dimensions of A starting by the outer one and filling with that B
B[0]=A[0,0,0,0]
B[1]=A[0,0,0,1]
B[nk-1]=A[0,0,0,nk-1]
B[nk]=A[0,0,1,0]
B[nk+1]=A[0,0,1,1]
and so on
Note that nk-1 corresponds to the zero-index notation so that if an array has N elements the last index is N-1.
You can check numpy docs

  
      numpy.org
  
  
    

numpy.reshape — NumPy v1.19 Manual 3



  
  
    
    
  
  


Since the logics are the same. There exist 2 types of ordering, fortran and c. In pytorch there is only C.
So the diff is ordering from outer to inner or inner to outer.