[Numpy-tickets] [NumPy] #263: Inconsistency in type shapes 1 and (1,)
NumPy
numpy-tickets at scipy.net
Sat Aug 19 04:53:11 CDT 2006
#263: Inconsistency in type shapes 1 and (1,)
------------------------+---------------------------------------------------
Reporter: faltet | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone: 1.0 Release
Component: numpy.core | Version:
Severity: normal | Keywords:
------------------------+---------------------------------------------------
I found what I think is an inconsistent behaviour in the shape
definition for datatypes in numpy. Look at this:
{{{
>>> dt1=numpy.dtype(numpy.int32)
>>> dt2=numpy.dtype((numpy.int32,(1,)))
>>> dt1.shape
(1,)
>>> dt2.shape
(1,)
}}}
I think that dt1 should have a different shape than dt2. In
particular, dt1 should have a shape == 1 instead of (1,).
The difference can be significant in cases like:
{{{
>>> numpy.arange(1,dtype=dt1)
array([0])
>>> numpy.arange(1,dtype=dt2)
array([[0]])
}}}
and, perhaps more importantly:
{{{
>>> type(numpy.arange(1,dtype=dt1)[0])
<type 'int32scalar'>
>>> type(numpy.arange(1,dtype=dt2)[0])
<type 'numpy.ndarray'>
}}}
in one case you get an int32scalar and in the other case an ndarray
object, although looking at the dtype object you cannot notice the
difference and you should, IMO.
Using 1.0b2 version, but 0.9.8 has the same behavior.
--
Ticket URL: <http://projects.scipy.org/scipy/numpy/ticket/263>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.
More information about the Numpy-tickets
mailing list