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.
1 Answer. To find the length of a numpy matrix in Python you can use shape which is a property of both numpy ndarray's and matrices. The above code will return a tuple (m, n), where m is the number of rows, and n is the number of columns.
size: This attribute calculates the total number of elements present in the NumPy array.
NumPy arrays have a fixed size at creation, unlike Python lists (which can grow dynamically). Changing the size of an ndarray will create a new array and delete the original. The elements in a NumPy array are all required to be of the same data type, and thus will be the same size in memory.
In NumPy array, all the elements have the same data type. itemsize returns the size (in bytes) of each element of a NumPy array. e.g. for this NumPy array [ [3,4,6], [0,8,1]], itemsize will be 8, because this array consists of integers and size of integer (in bytes) is 8 bytes.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With