[NumPy-Tickets] [NumPy] #2120: unravel_index(0, ()) should return ()
NumPy Trac
numpy-tickets@scipy....
Sun Apr 29 11:32:34 CDT 2012
#2120: unravel_index(0, ()) should return ()
-------------------------+--------------------------------------------------
Reporter: njs | Owner: somebody
Type: enhancement | Status: new
Priority: normal | Milestone: Unscheduled
Component: Other | Version: 1.6.1
Keywords: |
-------------------------+--------------------------------------------------
Currently, this idiom works for all arrays that have ndim >= 1:
{{{
for i in xrange(np.prod(a.shape)):
idx = np.unravel_index(i, a.shape)
a[idx] = ...
}}}
(Obviously there are usually better ways to do this, but anyway.)
But, it fails for 0-d arrays:
{{{
>>> np.unravel_index(0, ())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: dims must have at least one value
}}}
This should just return (), which is the unique index that can be used
with 0-d arrays.
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/2120>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list