summaryrefslogtreecommitdiff
path: root/numpy/lib/function_base.py
diff options
context:
space:
mode:
authorRalf Gommers <ralf.gommers@googlemail.com>2011-03-29 19:02:39 +0200
committerRalf Gommers <ralf.gommers@googlemail.com>2011-03-29 19:02:39 +0200
commitdce8638a727ea42ec97a407209ba0a722bf76380 (patch)
tree116e1fa20f64671a331272a00f67bd9c8fc89528 /numpy/lib/function_base.py
parenta6c2ac7f6312b3e8e553c548f2939405e16e44a6 (diff)
downloadnumpy-dce8638a727ea42ec97a407209ba0a722bf76380.tar.gz
BUG: make np.median() work for 0-D arrays. Also add tests. Closes #1747.
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r--numpy/lib/function_base.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index d30361dab..96c3f2a35 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -2838,14 +2838,14 @@ def median(a, axis=None, out=None, overwrite_input=False):
----------
a : array_like
Input array or object that can be converted to an array.
- axis : {None, int}, optional
+ axis : int, optional
Axis along which the medians are computed. The default (axis=None)
is to compute the median along a flattened version of the array.
out : ndarray, optional
Alternative output array in which to place the result. It must
have the same shape and buffer length as the expected output,
but the type (of the output) will be cast if necessary.
- overwrite_input : {False, True}, optional
+ overwrite_input : bool optional
If True, then allow use of memory of input array (a) for
calculations. The input array will be modified by the call to
median. This will save memory when you do not need to preserve
@@ -2911,6 +2911,9 @@ def median(a, axis=None, out=None, overwrite_input=False):
sorted = a
else:
sorted = sort(a, axis=axis)
+ if sorted.shape == ():
+ # make 0-D arrays work
+ return sorted.item()
if axis is None:
axis = 0
indexer = [slice(None)] * sorted.ndim