[SciPy-user] maximum_filter1d size parameter

Zachary Pincus zachary.pincus at yale.edu
Sun Mar 8 20:14:14 EDT 2009


> Thanks Josef, that explains it. What I will probably do is use a size
> twice as large as the number of rows.

If your intention is simply to calculate the maximum along the entire  
axis (which is what filtering with such a large kernel will do), you  
could use a.max(axis=0). This combined with some newaxis-es should  
give an array that broadcasts just like 'a' does.

Or if you really need an output array the exact same shape as 'a', but  
with the values filled in according to the max along the entire axis,  
you could probably do something bizarre with the strides like:
m = a.max(axis=0)
m_2d = numpy.ndarray(a.shape, a.dtype, m, strides = (a.itemsize, 0))

or
m = a.max(axis=1)
m_2d = numpy.ndarray(a.shape, a.dtype, m, strides = (0, a.itemsize))

Zach



> -Rick
>
> josef.pktd at gmail.com wrote:
>> On Sun, Mar 8, 2009 at 2:22 AM, Rick Giuly <rgiuly at gmail.com> wrote:
>>> Hello All,
>>>
>>> It seems I'm not understanding the "size" parameter for
>>> maximum_filter1d. The documentation says size is the "length along  
>>> which
>>> to calculate 1D maximum"
>>>
>>> Starting with this array:
>>>>>> a
>>> array([[1, 2, 3],
>>>       [4, 1, 1],
>>>       [1, 6, 7]])
>>>
>>>
>>> Because there are 3 rows in the matrix, it seems to me that with  
>>> size
>>> set to 3, the result of the filter would be:
>>> array([[4, 6, 7],
>>>       [4, 6, 7],
>>>       [4, 6, 7]])
>>>
>>>
>>> But the result is this:
>>>
>>>>>> maximum_filter1d(a, 3, axis=0)
>>> array([[4, 2, 3],
>>>       [4, 6, 7],
>>>       [4, 6, 7]])
>>>
>>>
>>> I don't see why.
>>>
>>> Any help is appreciated.
>>>
>>> -rick
>>
>> The filter is centered at the current point (keyword order=0), so at
>> the boundary it uses only the boundary point and the point next to  
>> it.
>> There are different modes (keyword mode), but none of them seem to
>> deliver what you want.
>>
>> I tried different mode and order combinations, but it seems changing
>> the order at the boundaries to use the filter in one direction only  
>> is
>> not possible.
>>
>> Josef
>> _______________________________________________
>> SciPy-user mailing list
>> SciPy-user at scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user




More information about the SciPy-User mailing list