Reputation: 923
suppose we have a 4-d matrix of shape (A,B,C,D), f. And we want to make such a transpose where we have f_transpose(i,j,k,c) = f(A-i+1,B-j+1,c,k). This is related to backpropagation of convnet, applying conv operator to get the gradient of conv layer. Can any one help me out?
Upvotes: 0
Views: 70
Reputation: 281207
You want to reverse the first two axes and switch the last two. Reversing an axis can be done with a ::-1
slice, and switching axes is numpy.swapaxes
:
g = numpy.swapaxes(f, 2, 3)[::-1, ::-1]
Upvotes: 2