Is there a reason why dtype's are unhashable ? (ouch) On another point, is there a canonical list of dtype's ? I'd like to test the dtype of an array, and I always end up with something like this: if array.dtype == numpy.dtype('l'): ... When I would prefer to write something like: if array.dtype == numpy.Int32: ... (i can never remember these char codes !) Alternatively, should dtype's __cmp__ promote the other arg to a dtype before the compare ? I guess not, since that would break a lot of code: eg. dtype(None) is legal. Simon. -- Simon Burton, B.Sc. Licensed PO Box 8066 ANU Canberra 2601 Australia Ph. 61 02 6249 6940 http://arrowtheory.com
Simon Burton wrote:
Is there a reason why dtype's are unhashable ? (ouch)
No one thought about it, probably. If you would like to submit a patch, I think it we would check it in.
On another point, is there a canonical list of dtype's ? I'd like to test the dtype of an array, and I always end up with something like this:
if array.dtype == numpy.dtype('l'): ...
When I would prefer to write something like:
if array.dtype == numpy.Int32: ...
numpy.int32 There is a list on page 20 of _The Guide to NumPy_. It is included in the sample chapters: http://www.tramy.us/scipybooksample.pdf
(i can never remember these char codes !)
Alternatively, should dtype's __cmp__ promote the other arg to a dtype before the compare ? I guess not, since that would break a lot of code: eg. dtype(None) is legal.
Correct, it should not. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
On Sun, 28 May 2006 14:33:37 -0500 Robert Kern <robert.kern@gmail.com> wrote:
if array.dtype == numpy.Int32: ...
numpy.int32
No that doesn't work.
numpy.int32 <type 'int32scalar'> numpy.int32 == numpy.dtype('l') False
Simon. -- Simon Burton, B.Sc. Licensed PO Box 8066 ANU Canberra 2601 Australia Ph. 61 02 6249 6940 http://arrowtheory.com
Simon Burton wrote:
On Sun, 28 May 2006 14:33:37 -0500 Robert Kern <robert.kern@gmail.com> wrote:
if array.dtype == numpy.Int32: ...
numpy.int32
No that doesn't work.
numpy.int32
<type 'int32scalar'>
numpy.int32 == numpy.dtype('l')
False
from numpy import * a = linspace(0, 10, 11) a.dtype == dtype(float64) True
-- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
Simon Burton wrote:
On Sun, 28 May 2006 14:33:37 -0500 Robert Kern <robert.kern@gmail.com> wrote:
if array.dtype == numpy.Int32: ...
numpy.int32
No that doesn't work.
Yeah, the "canonical" types (e.g. int32, float64, etc) are actually scalar objects. The type objects themselves are dtype(int32). I don't think they are currently listed anywhere in Python (except there is one for every canonical scalar object). The difference between the scalar object and the data-type object did not become clear until December 2005. Previously the scalar object was used as the data-type (obviously there is still a relationship between them). -Travis
numpy.int32
<type 'int32scalar'>
numpy.int32 == numpy.dtype('l')
False
Simon.
On Sun, 28 May 2006 14:36:47 -0600 Travis Oliphant <oliphant.travis@ieee.org> wrote:
Simon Burton wrote:
On Sun, 28 May 2006 14:33:37 -0500 Robert Kern <robert.kern@gmail.com> wrote:
if array.dtype == numpy.Int32: ...
numpy.int32
No that doesn't work.
Yeah, the "canonical" types (e.g. int32, float64, etc) are actually scalar objects. The type objects themselves are dtype(int32). I don't think they are currently listed anywhere in Python (except there is one for every canonical scalar object). ...
Can we promote the numarray names: Int32 etc. to their dtype equivalents ? I don't see why having Int32='l' is any more usefull that Int32=dtype('l'), and the later works with cmp (and also is more helpful in the interactive interpreter). Simon. -- Simon Burton, B.Sc. Licensed PO Box 8066 ANU Canberra 2601 Australia Ph. 61 02 6249 6940 http://arrowtheory.com
Simon Burton wrote:
On Sun, 28 May 2006 14:36:47 -0600 Travis Oliphant <oliphant.travis@ieee.org> wrote:
Simon Burton wrote:
On Sun, 28 May 2006 14:33:37 -0500 Robert Kern <robert.kern@gmail.com> wrote:
if array.dtype == numpy.Int32: ...
numpy.int32
No that doesn't work.
Yeah, the "canonical" types (e.g. int32, float64, etc) are actually scalar objects. The type objects themselves are dtype(int32). I don't think they are currently listed anywhere in Python (except there is one for every canonical scalar object).
...
Can we promote the numarray names: Int32 etc. to their dtype equivalents ?
Perhaps. There is the concern that it might break Numeric compatibility, though. -Travis
participants (3)
-
Robert Kern
-
Simon Burton
-
Travis Oliphant