I have an array:
import numpy as np
arr = np.random.randint(0,10,size=[8,8])
arr is:
array([[9, 1, 8, 2, 0, 4],
[0, 7, 6, 9, 7, 5],
[0, 7, 1, 6, 6, 2],
[3, 6, 3, 3, 8, 1]])
I want to reduce the size of this array using skimage.measure.block_reduce. I do
from skimage import measure as sm
reduced_arr = sm.block_reduce(arr, block_size=(4,6), func=np.max)
reduced_arr is:
array([[6, 7],
[9, 7]])
I try to achieve the same thing using a lambda function:
reduced_arr = sm.block_reduce(arr, block_size=(2,4), func= lambda block: np.max(block))
Then I get an error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-115-a11dc12d3db0> in <module>()
----> 1 reduced_arr = sm.block_reduce(arr, block_size=(2,4), func= lambda block: np.max(block))
/usr/local/lib/python3.7/dist-packages/skimage/measure/block.py in block_reduce(image, block_size, func, cval, func_kwargs)
85
86 return func(blocked, axis=tuple(range(image.ndim, blocked.ndim)),
---> 87 **func_kwargs)
TypeError: <lambda>() got an unexpected keyword argument 'axis'
How to use block_reduce with lambda functions?
My real world use case is more complicated than just a premade numpy function, that is why I need it.