slicing numpy array into two parts

Question:

I have a 2d numpy array
Something like this:

 [[ 1 2 3 4],
  [4,5,6,7]..
    ...... ] ]

Now I want to divide this into two parts.
lets say the first numpy array has the first two elements.
and the second numpy array has rest of the elements
something like this

B = [[1 2 3 4],
      [4 5 6 7]]
C = [[ rest of the elements]]

How do i do this
Thanks

Asked By: frazman

||

Answers:

This is covered in the Indexing, Slicing, and Iterating portion of the tutorial:

>>> import numpy as np
>>> A = np.array([[1,2,3,4],[4,5,6,7],[7,8,9,10]])
>>> B = A[:2]
>>> C = A[2:]
>>> B
array([[1, 2, 3, 4],
       [4, 5, 6, 7]])
>>> C
array([[ 7,  8,  9, 10]])
Answered By: jterrace
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.