user3413108
user3413108

Reputation:

2D Array - Select range of columns

I have a 2D numpy array A (MxN) and want to select a range of columns, lets say from m to n, (or rows - does not matter) like this:

A = A[m-n,:]

Is there a way to simply achieve this?

Upvotes: 1

Views: 3983

Answers (1)

sshashank124
sshashank124

Reputation: 32189

You can do it as:

B = A[m:n,:]

or if you want to include the n-th row:

B = A[m:n+1,:]

Similarly for columns:

C = A[:,m:n]

or

C = A[:,m:n+1]

Upvotes: 2

Related Questions