numpy.int32 is not subclass of int, but numpy.int64 is

Could someone explain this? An instance of numpy.int32 is not an instance of int or numpy.int. An instance of numpy.int64 is an instance of int and numpy.int. I don't know if it is a bug in my linux build. Andrew
python26 Python 2.6.2 (r262:71600, Jul 8 2010, 11:49:56) [GCC 4.1.2 20070115 (SUSE Linux)] on linux2 Type "help", "copyright", "credits" or "license" for more information.
import numpy a = numpy.array((1,2,3)) type(a[0])
<type 'numpy.int64'>
isinstance(a[0], int) True isinstance(a[0], numpy.int) True seven = numpy.int64(7) isinstance(seven, numpy.int) True isinstance(seven, int) True
five = numpy.int32(5) isinstance(five, numpy.int) False isinstance(five, int) False five 5 seven 7 issubclass(numpy.int64, numpy.int) True issubclass(numpy.int32, numpy.int) False
import sys sys.maxint 9223372036854775807 import platform print platform.platform() Linux-2.6.32.12-0.7-default-x86_64-with-SuSE-11-x86_64
This email and any attachments are intended solely for the use of the individual or entity to whom it is addressed and may be confidential and/or privileged. If you are not one of the named recipients or have received this email in error, (i) you should not read, disclose, or copy it, (ii) please notify sender of your receipt by reply email and delete this email and all attachments, (iii) Dassault Systemes does not accept or assume any liability or responsibility for any use of or reliance on this email. For other languages, go to http://www.3ds.com/terms/email-disclaimer

On Mon, Nov 14, 2011 at 20:18, MACKEITH Andrew <Andrew.MACKEITH@3ds.com> wrote:
Could someone explain this?
An instance of numpy.int32 is not an instance of int or numpy.int. An instance of numpy.int64 is an instance of int and numpy.int.
I don't know if it is a bug in my linux build.
import sys sys.maxint 9223372036854775807 import platform print platform.platform() Linux-2.6.32.12-0.7-default-x86_64-with-SuSE-11-x86_64
This is expected on a 64-bit platform. Note that numpy.int is just an alias for the builtin int type for backwards compatibility with an earlier version of numpy. We could probably remove it, since it seems to be causing more confusion than not. Anyways, we subclass the appropriately sized integer scalar type from Python's int type depending on the platform. So on a platform where Python's int type is 64-bits, numpy.int64 will include int in its inheritance tree. On platforms where the Python int type is 32-bit, numpy.int32 will include it instead. -- 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

2011/11/14 Robert Kern <robert.kern@gmail.com>
On Mon, Nov 14, 2011 at 20:18, MACKEITH Andrew <Andrew.MACKEITH@3ds.com> wrote:
Could someone explain this?
An instance of numpy.int32 is not an instance of int or numpy.int. An instance of numpy.int64 is an instance of int and numpy.int.
I don't know if it is a bug in my linux build.
import sys sys.maxint 9223372036854775807 import platform print platform.platform() Linux-2.6.32.12-0.7-default-x86_64-with-SuSE-11-x86_64
This is expected on a 64-bit platform. Note that numpy.int is just an alias for the builtin int type for backwards compatibility with an earlier version of numpy. We could probably remove it, since it seems to be causing more confusion than not.
Anyways, we subclass the appropriately sized integer scalar type from Python's int type depending on the platform. So on a platform where Python's int type is 64-bits, numpy.int64 will include int in its inheritance tree. On platforms where the Python int type is 32-bit, numpy.int32 will include it instead.
I'll just add that there is a numpy.integer class that is parent of both numpy.int32 and numpy.int64 (see http://docs.scipy.org/doc/numpy/reference/arrays.scalars.html). It's not a parent of numpy.int though, since as said above, numpy.int is an alias to the builtin int. -=- Olivier

From: numpy-discussion-bounces@scipy.org [mailto:numpy-discussion-bounces@scipy.org] On Behalf Of Olivier Delalleau Sent: Tuesday, November 15, 2011 7:03 AM To: Discussion of Numerical Python Subject: Re: [Numpy-discussion] numpy.int32 is not subclass of int, but numpy.int64 is 2011/11/14 Robert Kern <robert.kern@gmail.com<mailto:robert.kern@gmail.com>> On Mon, Nov 14, 2011 at 20:18, MACKEITH Andrew <Andrew.MACKEITH@3ds.com<mailto:Andrew.MACKEITH@3ds.com>> wrote:
Could someone explain this?
An instance of numpy.int32 is not an instance of int or numpy.int<http://numpy.int>. An instance of numpy.int64 is an instance of int and numpy.int<http://numpy.int>.
I don't know if it is a bug in my linux build.
import sys sys.maxint 9223372036854775807 import platform print platform.platform() Linux-2.6.32.12-0.7-default-x86_64-with-SuSE-11-x86_64 This is expected on a 64-bit platform. Note that numpy.int<http://numpy.int> is just an alias for the builtin int type for backwards compatibility with an earlier version of numpy. We could probably remove it, since it seems to be causing more confusion than not.
Anyways, we subclass the appropriately sized integer scalar type from Python's int type depending on the platform. So on a platform where Python's int type is 64-bits, numpy.int64 will include int in its inheritance tree. On platforms where the Python int type is 32-bit, numpy.int32 will include it instead. I'll just add that there is a numpy.integer class that is parent of both numpy.int32 and numpy.int64 (see http://docs.scipy.org/doc/numpy/reference/arrays.scalars.html). It's not a parent of numpy.int<http://numpy.int> though, since as said above, numpy.int<http://numpy.int> is an alias to the builtin int. -=- Olivier Thanks you for the information. numpy.integer is what I was looking for. Is there an equivalent base class for float types? Do you know where these are documented? Andrew This email and any attachments are intended solely for the use of the individual or entity to whom it is addressed and may be confidential and/or privileged. If you are not one of the named recipients or have received this email in error, (i) you should not read, disclose, or copy it, (ii) please notify sender of your receipt by reply email and delete this email and all attachments, (iii) Dassault Systemes does not accept or assume any liability or responsibility for any use of or reliance on this email. For other languages, go to http://www.3ds.com/terms/email-disclaimer

2011/11/15 MACKEITH Andrew <Andrew.MACKEITH@3ds.com>
*From:* numpy-discussion-bounces@scipy.org [mailto: numpy-discussion-bounces@scipy.org] *On Behalf Of *Olivier Delalleau *Sent:* Tuesday, November 15, 2011 7:03 AM *To:* Discussion of Numerical Python *Subject:* Re: [Numpy-discussion] numpy.int32 is not subclass of int, but numpy.int64 is
2011/11/14 Robert Kern <robert.kern@gmail.com>
On Mon, Nov 14, 2011 at 20:18, MACKEITH Andrew <Andrew.MACKEITH@3ds.com> wrote:
Could someone explain this?
An instance of numpy.int32 is not an instance of int or numpy.int. An instance of numpy.int64 is an instance of int and numpy.int.
I don't know if it is a bug in my linux build.
import sys sys.maxint 9223372036854775807 import platform print platform.platform() Linux-2.6.32.12-0.7-default-x86_64-with-SuSE-11-x86_64
This is expected on a 64-bit platform. Note that numpy.int is just an alias for the builtin int type for backwards compatibility with an earlier version of numpy. We could probably remove it, since it seems to be causing more confusion than not.
Anyways, we subclass the appropriately sized integer scalar type from Python's int type depending on the platform. So on a platform where Python's int type is 64-bits, numpy.int64 will include int in its inheritance tree. On platforms where the Python int type is 32-bit, numpy.int32 will include it instead.
I'll just add that there is a numpy.integer class that is parent of both numpy.int32 and numpy.int64 (see http://docs.scipy.org/doc/numpy/reference/arrays.scalars.html). It's not a parent of numpy.int though, since as said above, numpy.int is an alias to the builtin int.
-=- Olivier
Thanks you for the information. numpy.integer is what I was looking for.
Is there an equivalent base class for float types?
Do you know where these are documented?
Andrew
numpy.floating would be the one for non-complex float types (and numpy.inexact the parent for both complex and non-complex). The class hierarchy is shown in the link I provided in my previous mail. -=- Olivier

From: numpy-discussion-bounces@scipy.org [mailto:numpy-discussion-bounces@scipy.org] On Behalf Of Olivier Delalleau Sent: Tuesday, November 15, 2011 10:02 AM To: Discussion of Numerical Python Subject: Re: [Numpy-discussion] numpy.int32 is not subclass of int, but numpy.int64 is 2011/11/15 MACKEITH Andrew <Andrew.MACKEITH@3ds.com<mailto:Andrew.MACKEITH@3ds.com>> From: numpy-discussion-bounces@scipy.org<mailto:numpy-discussion-bounces@scipy.org> [mailto:numpy-discussion-bounces@scipy.org<mailto:numpy-discussion-bounces@scipy.org>] On Behalf Of Olivier Delalleau Sent: Tuesday, November 15, 2011 7:03 AM To: Discussion of Numerical Python Subject: Re: [Numpy-discussion] numpy.int32 is not subclass of int, but numpy.int64 is 2011/11/14 Robert Kern <robert.kern@gmail.com<mailto:robert.kern@gmail.com>> On Mon, Nov 14, 2011 at 20:18, MACKEITH Andrew <Andrew.MACKEITH@3ds.com<mailto:Andrew.MACKEITH@3ds.com>> wrote:
Could someone explain this?
An instance of numpy.int32 is not an instance of int or numpy.int<http://numpy.int>. An instance of numpy.int64 is an instance of int and numpy.int<http://numpy.int>.
I don't know if it is a bug in my linux build.
import sys sys.maxint 9223372036854775807 import platform print platform.platform() Linux-2.6.32.12-0.7-default-x86_64-with-SuSE-11-x86_64 This is expected on a 64-bit platform. Note that numpy.int<http://numpy.int> is just an alias for the builtin int type for backwards compatibility with an earlier version of numpy. We could probably remove it, since it seems to be causing more confusion than not.
Anyways, we subclass the appropriately sized integer scalar type from Python's int type depending on the platform. So on a platform where Python's int type is 64-bits, numpy.int64 will include int in its inheritance tree. On platforms where the Python int type is 32-bit, numpy.int32 will include it instead. I'll just add that there is a numpy.integer class that is parent of both numpy.int32 and numpy.int64 (see http://docs.scipy.org/doc/numpy/reference/arrays.scalars.html). It's not a parent of numpy.int<http://numpy.int> though, since as said above, numpy.int<http://numpy.int> is an alias to the builtin int. -=- Olivier Thanks you for the information. numpy.integer is what I was looking for. Is there an equivalent base class for float types? Do you know where these are documented? Andrew numpy.floating would be the one for non-complex float types (and numpy.inexact the parent for both complex and non-complex). The class hierarchy is shown in the link I provided in my previous mail. -=- Olivier Thanks. Andrew This email and any attachments are intended solely for the use of the individual or entity to whom it is addressed and may be confidential and/or privileged. If you are not one of the named recipients or have received this email in error, (i) you should not read, disclose, or copy it, (ii) please notify sender of your receipt by reply email and delete this email and all attachments, (iii) Dassault Systemes does not accept or assume any liability or responsibility for any use of or reliance on this email. For other languages, go to http://www.3ds.com/terms/email-disclaimer
participants (3)
-
MACKEITH Andrew
-
Olivier Delalleau
-
Robert Kern