user1764386
user1764386

Reputation: 5611

Python - split numpy array into unequally sized parts

I am trying to break a numpy array along a certain row so that I end up with a "top part" and a "bottom part."

example

[[2 1 3 2]   
 [1 6 7 2]
 [2 8 6 3]
 [3 4 2 2]]

top = [2 1 3 2]   

bottom = [[1 6 7 2]
          [2 8 6 3]
          [3 4 2 2]]

What is the easiest way to accomplish this? Right now I am copying the original array twice and deleting the parts I don't need. It seems like there should be an easy way to split the array into unequally sized parts. split and vsplit only seem to split into equally sized chunks. Any help is appreciated.

Upvotes: 0

Views: 2264

Answers (1)

PearsonArtPhoto
PearsonArtPhoto

Reputation: 39698

top=data[0]
bottom=data[1:3]

Basically, it's easy to slice the data as it is set up now. You could change the slice point easily if you needed to, using similar logic.

Upvotes: 4

Related Questions