# [Scipy-tickets] [SciPy] #1192: add ndimage.median function

SciPy Trac scipy-tickets@scipy....
Thu Jun 3 20:10:25 CDT 2010

---------------------------+------------------------------------------------
Reporter:  lmwang         |       Owner:  somebody
Type:  review         |      Status:  new
Priority:  normal         |   Milestone:  0.8.0
Component:  scipy.ndimage  |     Version:
Keywords:                 |
---------------------------+------------------------------------------------
I added an ndimage.median function to scipy/ndimage/measurements.py,
simply using labeled_comprehension that is in the trunk and numpy.median.

{{{
def median(input, labels = None, index = None):
"""
Calculate the median of the input array by label.

Parameters
----------

input : array_like
median of the values of `input` inside the regions defined by
`labels`
are calculated.

labels : array of integers, same shape as input
Assign labels to the values of the array.

index : scalar or array
A single label number or a sequence of label numbers of
the objects to be measured.

Returns
-------

output : array
An array of the median of the values of `input` inside the regions
defined by `labels`.

--------

mean

Examples
--------

>>> median(array([1,2,8,5, 2,4,6, 7]), labels=array([1,1,1,1, 2,2,2,
5]))
4.5
>>> median(array([1,2,8,5, 2,4,6, 7]), labels=array([1,1,1,1, 2,2,2,
5]), index=2)
4
>>> median(array([1,2,8,5, 2,4,6, 7]), labels=array([1,1,1,1, 2,2,2,
5]), index=array([1,5]))
array([3.5, 7])
>>> median(array([1,2,8,5, 2,4,6, 7]), labels=None, index=None))
4.5

"""

return labeled_comprehension(input, labels, index, numpy.median,
numpy.float, 0.0, pass_positions=False)
}}}

--
Ticket URL: <http://projects.scipy.org/scipy/ticket/1192>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.