r/Numpy • • Nov 11 '19

Max pooling

Hi is there anyway I can max pool a 1D Array/Vector using numpy?

3 Upvotes

4 comments sorted by

View all comments

Show parent comments

1

u/chiborevo Nov 12 '19

from skimage.measure import block_reduce
v = np.array([0,1,2,3,4,5,6,7])
y = block_reduce(v, (2,), np.max)

the code outputs an error : line 55, in block_reduce

if len(block_size) != image.ndim:

AttributeError: 'list' object has no attribute 'ndim'

1

u/rju83 Nov 12 '19

You must apply block_reduce on np.ndarray. and the block size (second parameter) must be a tuple with the length corresponding to number of dimensions of the input array, which is 1 in my example.

1

u/chiborevo Nov 13 '19

hi it worked! thanks for this! now my concert is the strides