How to crop array into specific size, in here 32x32. from left top to right? is there built-in to this ways? i read somewhere implement manual ways, make numpy slower. so i think can improve this manipulation.
import numpy
frame = numpy.full((1080, 1920), 255)
frameBlocks = numpy.array()
wBlock = 32
hBlock = 32
# Determine total block each row because sometime the latest block not exactly fit size.
wBlockLength = numpy.floor(frame.shape[1] / wBlock)
hBlockLength = numpy.floor(frame.shape[0] / hBlock)
# Crop from left to right with 32 x 32
for hBL in range(0, hBlockLength):
hIndex = hBL*hBlock
for wBL in range(0, wBlockLength):
block = numpy.zeros(wBlock, hBlock)
wIndex = wBL*wBlock
for hB in range(0, hBlock):
for wB in range(0, wBlock):
block[hB][wB] = frame[hIndex][wIndex]
wIndex += 1
hIndex += 1
frameBlocks.append(block)
# create index order to shuffle
blocksLength = len(frameBlocks)
index = numpy.array(range(0, blocksLength))
# Shuffle order by index
frameBlocks[index]
my other question how to turn blocks that already suffle into frame? exactly it simple just repeat that loop again. but, how about in numpy ways?