Form a big 2d array from multiple smaller 2d arrays

前端 未结 5 660
囚心锁ツ
囚心锁ツ 2020-12-01 02:44

The question is the inverse of this question. I\'m looking for a generic method to from the original big array from small arrays:

array([[[ 0,  1,  2],
             


        
5条回答
  •  -上瘾入骨i
    2020-12-01 03:04

    It works for the images I tested for now. Will if further tests are made. It is however a solution which takes no account about speed and memory usage.

    def unblockshaped(blocks, h, w):
        n, nrows, ncols = blocks.shape
        bpc = w/ncols
        bpr = h/nrows
    
        reconstructed = zeros((h,w))
        t = 0
        for i in arange(bpr):
            for j in arange(bpc):
                reconstructed[i*nrows:i*nrows+nrows,j*ncols:j*ncols+ncols] = blocks[t]
                t = t+1
        return reconstructed
    

提交回复
热议问题