Swap slices of Numpy arrays
Python correctly interprets the code as if you used additional variables, so the swapping code is equivalent to: t1 = b[:,0,0] t2 = a[:,0,0] a[:,0,0] = t1 b[:,0,0] = t2 However, even this code doesn’t swap values correctly! This is because Numpy slices don’t eagerly copy data, they create views into existing data. Copies are … Read more