numpy / numpy

The fundamental package for scientific computing with Python.
https://numpy.org
Other
28.18k stars 10.16k forks source link

Function rank() return bad value #4616

Closed mailoszyarr closed 10 years ago

mailoszyarr commented 10 years ago

Hi, for matrix [[1, 2], [-1, -2]] rank() returns 2, but real value is 1. It is very big issue for Control Systems Engineers - we couldn't detect controlability and observabiliti of MIMO system.

jaimefrio commented 10 years ago

You want to use np.linalg.matrix_rank, not np.rank. For ndarrays rank returns the same as .ndim.

In [1]: import numpy as np

In [2]: a = np.array([[1, 2], [-1, -2]])

In [3]: np.rank(a)
Out[3]: 2

In [4]: np.linalg.matrix_rank(a)
Out[4]: 1
seberg commented 10 years ago

Sounds indeed like you got the wrong function. A bit of a misnomer. Considering that rank is really a leftover from numeric and call it ndim we might want to consider deprecating it?

charris commented 10 years ago

@seberg Probably a good idea, IIRC, there was recently another instance of this confusion.

jaimefrio commented 10 years ago

I have seen it a couple times on StackOverflow.

matthew-brett commented 10 years ago

rank(A) in matlab is the matrix rank.

ndim is surely a better name.

I vote for deprecation too.

cimarronm commented 10 years ago

I vote for deprecation too...it should be ndim and not rank

njsmith commented 10 years ago

I vote we immediately put in a user-visible warning that says "this is deprecated and also you probably wanted np.linalg.matrix_rank", to stem the confusion as soon as possible without actually breaking compatibility. On 12 Apr 2014 22:45, "Cimarron" notifications@github.com wrote:

I vote for deprecation too...it should be ndim and not rank

— Reply to this email directly or view it on GitHubhttps://github.com/numpy/numpy/issues/4616#issuecomment-40292643 .

seberg commented 10 years ago

Would be fine with me, too. But visible means we can't use DeprecationWarning...

seberg commented 10 years ago

It is a bit funky, but we could do both a DeprecationWarning and a UserWarning...