I have a numpy array, say
([1,2,3,4,5,6,7])
I want to split it into a 2d array such that the last element is in its own array, like this
([1,2,3,4,5,6],[7])
How exactly would I do this?
I have a numpy array, say
([1,2,3,4,5,6,7])
I want to split it into a 2d array such that the last element is in its own array, like this
([1,2,3,4,5,6],[7])
How exactly would I do this?
Use np.split -
np.split(a,[-1])
Sample run -
In [105]: a
Out[105]: array([1, 2, 3, 4, 5, 6, 7])
In [106]: np.split(a,[-1])
Out[106]: [array([1, 2, 3, 4, 5, 6]), array([7])]