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
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]])
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
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]])