python - numpy nonzero() returns indexes sorted by row index? -


as in matlab, nonzeros return indexes ordered columns(http://www.mathworks.com/help/matlab/ref/nonzeros.html). in numpy, seems returned indexes ordered rows (for 2d matrix). not articulated in doc (http://docs.scipy.org/doc/numpy/reference/generated/numpy.nonzero.html). safe assume that?

an example:

test = np.array([[0,2], [3,0]]) test[test.nonzero()] 

gives array([2, 3]) instead of array([3, 2])

there following comment on c source code of pyarray_nonzero, c function handles calls nonzero:

/*numpy_api  * nonzero  *  * todo: in numpy 2.0, should make iteration order parameter.  */ npy_no_export pyobject * pyarray_nonzero(pyarrayobject *self) 

the iteration order is hardcoded c-order, i.e. last index varies fastest, i.e. sorted rows, columns, 2d case. given comment, safe assume that, if ever changes, providing new functionality defaults current behavior.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -