splitting numpy array unevenly

W

Wanderer

I need to divide a 512x512 image array with the first horizontal and vertical division 49 pixels in. Then every 59 pixels in after that. hsplit and vsplit want to start at the edges and create a bunch of same size arrays. Is there a command to chop off different sized arrays?

Thanks
 
M

Martin De Kauwe

I need to divide a 512x512 image array with the first horizontal and vertical division 49 pixels in. Then every 59 pixels in after that. hsplit and vsplit want to start at the edges and create a bunch of same size arrays. Is there a command to chop off different sized arrays?



Thanks

I don't know that I follow completely, but can't you just slice what you are after?

x = np.random.rand(512*512).reshape(512,512)
xx = x[0,:49]
And put the rest of the slices in a loop...?
 
W

Wanderer

I need to divide a 512x512 image array with the first horizontal and vertical division 49 pixels in. Then every 59 pixels in after that. hsplit and vsplit want to start at the edges and create a bunch of same size arrays.Is there a command to chop off different sized arrays?



Thanks



I don't know that I follow completely, but can't you just slice what you are after?



x = np.random.rand(512*512).reshape(512,512)

xx = x[0,:49]

And put the rest of the slices in a loop...?

I was trying to avoid the loop. I figured it out. hsplit and vsplit will work. I just need to give it a list of break points. I still need a loop though.

breakPoints = range(49,512,59)
rowArrays = hsplit(InputArray, breakPoints)
OutArrays = []
for r in rowArrays:
OutArrays.append(vsplit(r, breakPoints))
 
H

Hans Mulder

I need to divide a 512x512 image array with the first horizontal
and vertical division 49 pixels in. Then every 59 pixels in after
that. hsplit and vsplit want to start at the edges and create a
bunch of same size arrays. Is there a command to chop off
different sized arrays?
I don't know that I follow completely, but can't you just slice
what you are after?
x = np.random.rand(512*512).reshape(512,512)
xx = x[0,:49]
And put the rest of the slices in a loop...?
I was trying to avoid the loop. I figured it out. hsplit and vsplit
will work. I just need to give it a list of break points. I still
need a loop though.
breakPoints = range(49,512,59)
rowArrays = hsplit(InputArray, breakPoints)
OutArrays = []
for r in rowArrays:
OutArrays.append(vsplit(r, breakPoints))

How about a list display:

breakPoints = range(49,512,59)
rowArrays = hsplit(InputArray, breakPoints)
OutArrays = [vsplit(r, breakPoints) for r in rowArrays]

In some sense, it's still a loop, but at least it doesn't look like one.


Hope this helps,

-- HansM
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top