This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from https://stackoverflow.com/questions/42463172/how-to-perform-max-mean-pooling-on-a-2d-array-using-numpy | |
import numpy as np | |
def asStride(arr,sub_shape,stride): | |
'''Get a strided sub-matrices view of an ndarray. | |
See also skimage.util.shape.view_as_windows() | |
''' | |
s0,s1=arr.strides[:2] | |
m1,n1=arr.shape[:2] | |
m2,n2=sub_shape | |
view_shape=(1+(m1-m2)//stride[0],1+(n1-n2)//stride[1],m2,n2)+arr.shape[2:] |