question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

median of np.matrix is broken

See original GitHub issue
>>> import numpy as np                                                          
>>> a = np.matrix([[0, 1, 2]])                                                  
>>> np.mean(a)                                                                  
1.0
>>> np.median(a)                                                                
Traceback (most recent call last):
[...]
/numpy/core/fromnumeric.py", line 619, in partition
    a.partition(kth, axis=axis, kind=kind, order=order)
ValueError: kth(=1) out of bounds (1)

Issue Analytics

  • State:open
  • Created 10 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dipsivenkateshcommented, Mar 24, 2022

Reproducing Bug:

This bug seems to exist when we compute median for NumPy matrix, and that too when we don’t specify the axis.

a = np.matrix([[0,1,2],[3,4,5]])
>>> np.median(a)
matrix([[0., 1., 2., 3., 4., 5.]])
>>> np.median(a,axis = 1)
matrix([[1.],
        [4.]])
>>> np.median(a,axis = 0)
matrix([[1.5, 2.5, 3.5]])

for numpy array, it flattens the array and computes the median but for the matrix it’s not.

0reactions
charriscommented, Jan 1, 2017

Heh, still present in 1.12.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use the NumPy median function - Sharp Sight
The NumPy median function computes the median of the values in a NumPy array. Note that the NumPy median function will also operate...
Read more >
Numpy median-of-means computation across unequal-sized ...
This program works fine if b divides m since np.array_split() results in partitioning the indices in equal parts and array buckets is a...
Read more >
How to Use median() in NumPy? - Spark by {Examples}
Python NumPy median() function is used to compute the median of the given NumPy array over the specified axis or multiple axes.
Read more >
numpy.median() in Python - GeeksforGeeks
Parameters : arr : [array_like]input array. axis : [int or tuples of int]axis along which we want to calculate the median. Otherwise ...
Read more >
numpy.median — NumPy v1.24 Manual
Axis or axes along which the medians are computed. The default is to compute the median along a flattened version of the array....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found