Aggregate Numpy Array By Summing

前端 未结 3 1226
耶瑟儿~
耶瑟儿~ 2021-01-21 01:37

I have a Numpy array of shape (4320,8640). I would like to have an array of shape (2160,4320).

You\'ll notice that each cell of the new array m

3条回答
  •  一向
    一向 (楼主)
    2021-01-21 02:16

    I'm not sure there exists the package you want, but this code will compute much faster.

    >>> arrtrans2 = arr[::2, ::2] + arr[::2, 1::2] + arr[1::2, ::2] + arr[1::2, 1::2]
    >>> numpy.allclose(arrtrans, arrtrans2)
    True
    

    Where ::2 and 1::2 are translated by 0, 2, 4, ... and 1, 3, 5, ... respectively.

提交回复
热议问题