# How to get a sub range of a larger matrix?

This should be an easy question but I only found a partial solution using All.

Say I have a matrix A = 1000 x 5, how to get only a part of that matrix, say B = n x 5, where n can be any positive integer that's less than 1000 or the original matrix A row?

You can make good use of Span in multiple dimensions:

m = Table[{y, x}, {y, 1, 5}, {x, 1, 10}];

m[[2 ;; 3, 5 ;; 6]]


{{{2, 5}, {2, 6}}, {{3, 5}, {3, 6}}}

(verbatim @J.M.)...Take[] works nicely as well:

Take[m, {2, 3}, {5, 6}]


{{{2, 5}, {2, 6}}, {{3, 5}, {3, 6}}}

• Take[] works nicely as well: Take[m, {2, 3}, {5, 6}] – J. M.'s technical difficulties Nov 12 '12 at 9:27
• @J.M. another answer? Strangely, I almost never use Take in my code... so much for cerebral plasticity. – Yves Klett Nov 12 '12 at 13:50
• I'd prefer that you just append it to your answer... :) – J. M.'s technical difficulties Nov 12 '12 at 14:03
• @J.M. Ta(l)king about low-hanging fruit :-) – Yves Klett Nov 12 '12 at 14:10

I guess this should work, if I need the second and third rows of a matrix :

{{a, b, c}, {d, e, f}, {g, h, i}}[[2 ;; 3]]