Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numpy/scipy deprecation warning for "rank"

I have some python code which uses numpy and have run this successfully for a year or more. I suddenly got the following error last week:

/usr/local/lib/python2.7/dist-packages/numpy/core/fromnumeric.py:2507: VisibleDeprecationWarning: `rank` is deprecated; use the `ndim` attribute or function instead. To find the rank of a matrix see `numpy.linalg.matrix_rank`.
  VisibleDeprecationWarning)

I can't find much on this online, but I found a suggestion that this was due to a bug in old versions of scipy (although my code doesn't actually use scipy directly). I've upgraded to python 2.7.9 with numpy 1.9.2 and scipy 0.15.1, however I'm still getting the same error. I'm not sure what's causing this, or how I fix this.

like image 335
218 Avatar asked Apr 20 '15 17:04

218


1 Answers

From the release notes of NumPy 1.9.0:

rank function

The rank function has been deprecated to avoid confusion with numpy.linalg.matrix_rank.

It seems the developers saw fit to reserve the word "rank" to mean the number of linearly independent rows an array has, and not use it to also mean the number of dimensions.

This function won't be present in major future releases of NumPy. Therefore, instead of using np.rank to find the number of dimensions in an array, follow the suggestion in the warning and use the ndim attribute of an array or the function np.ndim instead.

If you simply want to suppress the warning for now, the warnings module allows you to ignore the messages.

like image 104
Alex Riley Avatar answered Oct 12 '22 06:10

Alex Riley