Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a numpy biginteger?

Hmm. There doesn't seem to me a way to store Python's bigintegers in a numpy array. Is there something special you have to do, to declare a numpy array with bigints?

like image 961
Jason S Avatar asked Feb 17 '15 00:02

Jason S


People also ask

What are NumPy data type?

NumPy dtypeA data type object implements the fixed size of memory corresponding to an array. We can create a dtype object by using the following syntax. The constructor accepts the following object. Object: It represents the object which is to be converted to the data type.

Can NumPy arrays have different data types?

Can an array store different data types? Yes, a numpy array can store different data String, Integer, Complex, Float, Boolean.

Is CuPy faster than NumPy?

50x Faster NumPy = CuPy.

What is NumPy uint8?

NumPy data types uint8 In Python uint8 datatype indicates unsigned integer and it consists of 8 bits with positive range values from 0 to 255. This datatype store information about the type byte order and bit-width with 'C'unsigned character.


1 Answers

Not specifically, no. You can create an array with dtype='object', which creates an array of Python objects (including but not limited to ints). This will get you a lot of Numpy array-like functionality but few to none of the performance benefits.

Which is to say, an array of Python objects is not significantly different from a Python list in terms of memory performance. Though if you must use bigints it may still be preferable to using a list since you still get element-wise arithmetic operations, including when doing operations with other Numpy arrays. For example:

In [1]: import numpy as np

In [2]: big = np.array([10**100, 10**101, 10**102], dtype='object')

In [3]: big
Out[3]: 
array([ 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,
       100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000,
       1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000], dtype=object)

In [4]: big + np.array([1, 2, 3])
Out[4]: 
array([ 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001,
       100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002,
       1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003], dtype=object)

I've never used this capability myself though, so I'm not entirely sure what other surprising limitations might arise.

like image 61
Iguananaut Avatar answered Sep 20 '22 19:09

Iguananaut