Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python: converting an numpy array data type from int64 to int

Tags:

I am somewhat new to python and I am using python modules in another program (ABAQUS). The question, however, is completely python related.

In the program, I need to create an array of integers. This array will later be used as an input in a function defined in ABAQUS. The problem is to do with the data type of the integers. In the array, the integers have data type 'int64'. However, I am getting the following error when I input the array to the desired function:

"Only INT, FLOAT and DOUBLE supported by the ABAQUS interface (use multiarray with typecode int if standard long is 64 bit)"

I do not need assistance with ABAQUS. If i convert the data type to 'int' in python, that would suffice. I thought that I could simply use the int() function to convert the data type. This did not work. Any suggestions will be highly appreciated. Thank you all.

like image 648
Srikanth Avatar asked Sep 28 '12 23:09

Srikanth


People also ask

How do I convert a Numpy array to integer?

To convert numpy float to int array in Python, use the np. astype() function. The np. astype() function takes an array of float values and converts it into an integer array.

What does int64 mean in Numpy?

So the byte length is 8. I think 'np.int64()' means an integer in (-9223372036854775808 to 9223372036854775807) or an unsigned integer in (0 to 18446744073709551615)

Is int64 int Python?

You will often see the data type Int64 in Python which stands for 64 bit integer. The 64 refers to the memory allocated to store data in each cell which effectively relates to how many digits it can store in each “cell”. Allocating space ahead of time allows computers to optimize storage and processing efficiency.


1 Answers

numpy.ndarray.tolist will do it:

a.tolist() 

If your data is a pandas series you can call their tolist wrapper with the same result.

like image 64
bigonazzi Avatar answered Sep 22 '22 05:09

bigonazzi