10

It doesn't appear to be 'bitness' (32 vs. 64) of the processor, see comments on this post, in particular:

Good answer. As I mentioned in my comments above, I'm able to duplicate @suzep136's issue on a Raspberry Pi 3, which uses a 64-bit ARM processor. Any idea why the overflow issue would occur on a 64-bit architecture? The only thing I can think of is that lapack/blas were compiled for a 32-bit core; I think I installed numpy through apt-get. – nrlakin

Nor is it the size of int in C, for example on my machine:

>>> import numpy, ctypes
>>> 
>>> ctypes.sizeof(ctypes.c_int)
4
>>> numpy.array([1]).dtype
dtype('int64')

So, what does it depend on?

Edit: There goes another candidate, thanks ev-br:

LAPACK uses 32-bit integers on all architectures – ev-br

Edit: A partial answer is here. Thanks Goyo. I've copied this and made it CW so you can add the finer points such as what happens in PyPy or Jython. I'd also be interested in whether there are any deeper reasons for this choice.

12
  • You can check the datatype that int corresponds to using numpy.dtype(int). Commented Jan 21, 2017 at 18:21
  • @EliSadoff thanks, but that only gives me the what, not the why. Commented Jan 21, 2017 at 19:04
  • LAPACK uses 32-bit integers on all architectures Commented Jan 21, 2017 at 19:13
  • @ev-br interesting. Perhaps you could copy your comment to the linked post, so nrlakin will see it? Commented Jan 21, 2017 at 19:18
  • 3
    Possible duplicate of numpy array dtype is coming as int32 by default in a windows 10 64 bit machine Commented Jan 21, 2017 at 19:52

2 Answers 2

2

Thanks to Goyo who is too modest to take the credit. See their answer to a related but different question.

The default integer type in numpy is numpy.int_, be sure to notice the trailing underline. It defaults to C long 1.

Sign up to request clarification or add additional context in comments.

Comments

0

Ok, so I may be misunderstanding your question but if you take a look at the Numpy Documentation my guess would be that numpy assigns bit values based on what the max bit size could go up or down to given the system architecture. Basically, because you did not specify that the integer "container" only need be 8 or 16 bits in length it defaulted to the largest container possible on a 64 bit machine.

If you want to find the number of bits python has a builtin "bit_length()" function. Check it out here: https://docs.python.org/3.6/library/stdtypes.html#int.bit_length

Hope this answers your question.

No, that is precisely not what happens. In a sense the whole point of the question is that what you and I and others naively assume is not correct.

Your Answer

Draft saved
Draft discarded

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.