Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
if hasattr(v, 'median'): return v.median()

if len(v) == 0:
    # Median of empty set defined as NaN
    return NaN
values = sorted(v)
if len(values) % 2 == 1:
    return values[((len(values))+1)/2-1]
else:
    lower = values[(len(values)+1)/2-1]
    upper = values[len(values)/2]
    return (lower + upper)/ZZ(2)