How to Delete in-place First row and column (activationMap) in Pytorch

I want to remove first row and first column from an intermediate activation map, but i get the following error–

RuntimeError: Need gradOutput of dimension 4 and gradOutput.size[2] == 5 but got gradOutput to be of shape: [20 x 512 x 4 x 4] at /Users/soumith/miniconda2/conda-bld/pytorch_1490984005896/work/torch/lib/THNN/generic/SpatialConvolutionMM.c:51

For example, if below is an intermediate activation map, I want to remove first row and column from each activation map –

(0 ,0 ,.,.) =
0 0 0 0
0 1 1 1
0 1 1 1
0 1 1 1
(0 ,1 ,.,.) =
0 0 0 0
0 1 1 1
0 1 1 1
0 1 1 1
(1 ,0 ,.,.) =
0 0 0 0
0 1 1 1
0 1 1 1
0 1 1 1
(1 ,1 ,.,.) =
0 0 0 0
0 1 1 1
0 1 1 1
0 1 1 1
[torch.FloatTensor of size 2x2x4x4]

I use x.resize_(2,2,3,3) to do that.

Hi,

the result of the resize_ function is a tensor containing garbage data, I don’t think you want to use it here.
You can use the narrow method to select only the part of the tensor you want or advanced indexing:

# Using narrow
out = in.narrow(-2, 1, 3).narrow(-1, 1, 3)
# Using advanced indexing
out = in[:, :, 1:, 1:]

But doing out = in[:, :, 1:, 1:], will not give you in-place operation and how the gradients will flow after that then ?

Even after doing that i get the same error –
RuntimeError: Need gradOutput of dimension 4 and gradOutput.size[2] == 5 but got gradOutput to be of shape: [20 x 512 x 4 x 4] at /Users/soumith/miniconda2/conda-bld/pytorch_1490984005896/work/torch/lib/THNN/generic/SpatialConvolutionMM.c:51

What do you mean by inplace operation? Here, changing out will change in as well, so it is inplace in that sense.
If you mean inplace as changing in directly, that is not possible.

Why do you want to do that?