# Inverse of ArrayPad operation, or removal of first column and first row of matrix [duplicate]

I have some large matrices, which I need to remove the first row and first column (both of which are full of zeroes). In this sense I need the inverse of "ArrayPad".

For example, consider the matrix:

A = {{0, 0, 0, 0}, {0, 1, 2, 3}, {0, 4, 5, 6} , {0, 7, 8, 9}}
A // MatrixForm


I would like an operation to reduce it to

Anew =  {{1, 2, 3}, {4, 5, 6} , {7, 8, 9}}
Anew // MatrixForm


I need general recipe for such operation for to go from (N+1) by (N+1) matrix to N by N matrix by removing the first column of zeroes and first row of zeroes.

Any help appreciated.

• A[[2;;,2;;]] 15char – LLlAMnYP Sep 3 '16 at 11:17
• f=Drop[#,1]& drops the first element of a list. f=Drop[#,-1]& drops the last. f[A] removes rows. f/@A removes columns. – mikado Sep 3 '16 at 11:31
• This question is answered in: (17002), (20228), (76109) – Mr.Wizard Sep 4 '16 at 14:30

Rest is the built-in function for removing the first element from a list, so given

m = {{0, 0, 0, 0}, {0, 1, 2, 3}, {0, 4, 5, 6}, {0, 7, 8, 9}};


then

Rest[Rest /@ m]


produces

{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}

as does

Rest /@ Rest[m]

m0 =  {{1,2,3},{4,5,6},{7,8,9}};


{{0,0,0,0}, {0,1,2,3},{0,4,5,6},{0, 7,8,9}}

m2 = ArrayPad[m1, -{{1,0},{1, 0}}]


{{1,2,3},{4,5,6},{7,8,9}}

• Weird! Probably the closest fit to the description "inverse of ArrayPad" here. – Lucas Sep 5 '16 at 6:10

You can use the [[ ]] notation, which is backed by Part. You just need to start from an index of 2. i.e.

A[[2 ;;, 2 ;;]]


For example, if we have a matrix x given by

x = Table[j + 4 i + 1, {i, 0, 3}, {j, 0, 3}];
x // MatrixForm


$\left( \begin{array}{cccc} 1 & 2 & 3 & 4 \\ 5 & 6 & 7 & 8 \\ 9 & 10 & 11 & 12 \\ 13 & 14 & 15 & 16 \\ \end{array} \right)$

Then the operation

x[[2 ;;, 2 ;;]]


gives

% // MatrixForm


$\left( \begin{array}{ccc} 6 & 7 & 8 \\ 10 & 11 & 12 \\ 14 & 15 & 16 \\ \end{array} \right)$