Hollow out an array
MATL, 9 bytes
0HJ_ht4$(
Input is in the format
[67 4 -8 5 13; 9 13 42 4 -7; 1 1 3 -9 29; 16 99 8 77 0]
EDIT (June 12, 2016): to adapt to changes in the language, the link below has _
replaced by q
.
Try it online!
0 % Push a 0: value that will be assigned into the array
HJ_h % Vector [2, -1j]: this corresponds to index 2:end-1 for rows
t % Duplicate: same index for columns
4$( % Assignment indexing with 4 inputs: array, new value, row and col indices
% Since the first input (array) to this function is currently missing, it's
% implicitly taken at this point from stdin
% Implicitly display stack contents, which is the modified array
Java 7, as a fully named function: 85
void f(int[][]a){for(int i=0,j;++i<a.length-1;)for(j=1;j<a[i].length-1;)a[i][j++]=0;}
You could lambda this down in Java 8 to remove a few bytes, but I don't really do that.
Jelly, 18 17 15 9 bytes
0W&ṖZ
ÇÇ^
Try it online! or verify all test cases.
Background
This approach is based on @Sp3000's Jelly answer, specifically on his idea to take advantage of vectorized operations between lists of different lengths.
We start by taking the bitwise AND of 0 and every integer in the first row of the input. Due to automatic vectorization, this can be achieved by taking the bitwise AND of [0] and the input without its last row. 0 is paired with the first row, resulting in a row of zeroes. Since the remaining rows have no counterpart in [0], they are left untouched.
Now we transpose the result, apply the above transformation once again (effectively removing the last column and zeroing out the first), and transpose again.
For the input
67 4 -8 5 13
9 13 42 4 -7
1 1 3 -9 29
16 99 8 77 0
this results in
0 0 0 0
0 13 42 4
0 1 3 -9
Now, we take the bitwise XOR of this result and the original matrix. XORing an integer with itself yields 0. XORing an integer with 0 (or not XORing it at all) yields the same integer. This hollows the matrix out.
How it works
0W&ṖZ Helper link. Argument: M (matrix)
0W Yield [0].
Ṗ Yield M, without its last row.
& Take the bitwise AND of both.
Z Zip the result.
ÇÇ^ Main link. Input: A (matrix)
Ç Call the helper link on A.
Ç Call the helper link on the result.
^ Take the bitwise XOR of the result and A.