Given a convolutional layer, I am interested in recovering the weight matrix $W$, where $w_{i,j}$ is the weight between neuron $i$ in the input layer and neuron $j$ in the output layer. I know that most of these will be zero (e.g. for a 3x3 kernel there will only be 9 nonzero elements). In other words, I want to find the equivalent fully-connected layer to this convolutional layer.
Bonus points for any pytorch code.