In [8]: import numpy as np

In [9]: a = np.array([1,2,3,4,5])

In [10]: int("".join(map(str, a)))
Out[10]: 12345
Answer from Akavall on Stack Overflow
Top answer
1 of 5
4
In [8]: import numpy as np

In [9]: a = np.array([1,2,3,4,5])

In [10]: int("".join(map(str, a)))
Out[10]: 12345
2 of 5
3

Just use the sum() function with a generator:

>>> sum(e * 10 ** i for i, e in enumerate(x[::-1]))
12345

or, alternatively:

>>> sum(e * 10 ** (len(x) - i-1) for i, e in enumerate(x))
12345

or you could use str.join, again with a generator:

>>> int(''.join(str(i) for i in x))
12345

why?

In the first example, we use a generator to yield each number multiplied by 10 to the power of its position in the array, we then add these together to get our final result. This may be easier to see if we use a list-comprehension, rather than a generator to see what is going on:

>>> [e * 10 ** i for i, e in enumerate(x[::-1])]
[5, 40, 300, 2000, 10000]

and then it is clear from here that, through summing these numbers together, we will get the result of 12345. Note, however, that we had to reverse x before using this, as otherwise the numbers would be multiplied by the wrong powers of 10 (i.e. the first number would be multiplied by 1 rather than 10000).

In the second snippet, the code simply uses a different method to get the right power of 10 for each index. Rather than reversing the array, we simply subtract the index from the length of x (len(x)), and minus one more so that the first element is 10000, not 100000. This is simply an alternative.

Finally, the last method should be fairly self-explanatory. We are merely joining together the stringified versions of each number in the array, and then converting back to an int to get our result.

🌐
Saturn Cloud
saturncloud.io › blog › converting-numpy-array-values-into-integers-a-comprehensive-guide
Converting Numpy Array Values into Integers: A Guide | Saturn Cloud Blog
May 1, 2026 - Numpy provides several functions to convert the data types of numbers. The astype() function is one of the most commonly used functions for this purpose. Let’s dive into how you can use this function to convert Numpy array values into integers.
Discussions

python - Convert ndarray from float64 to integer - Stack Overflow
I've got an ndarray in python with a dtype of float64. I'd like to convert the array to be an array of integers. How should I do this? int() won't work, as it says it can't convert it to a scalar. More on stackoverflow.com
🌐 stackoverflow.com
python - Convert Numpy array with 'n' and 'y' into integer array of 0 and 1 - Data Science Stack Exchange
Data Science is part of Stack ... and the best answers rise to the top. Find your community · The 2026 Annual Developer Survey Results Site is live— view the results here!. ... I have a NumPy array of strings: 'n', 'y', wanna convert it into integer array of 0, 1, how ... More on datascience.stackexchange.com
🌐 datascience.stackexchange.com
January 10, 2020
python - convert array([[ number ]]) to 'number' - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
machine learning - Creating a single number from a numpy array - Python - Data Science Stack Exchange
If the author adds details in comments, consider editing them into the question. Once there's sufficient detail to answer, vote to reopen the question. Closed 8 years ago. ... I am working on a gender classification project. I am extracting the pixels of an image using a Numpy array in Python, ... More on datascience.stackexchange.com
🌐 datascience.stackexchange.com
October 2, 2018
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-convert-numpy-array-of-floats-into-integers
How to Convert NumPy Array of Floats into Integers - GeeksforGeeks
July 23, 2025 - Converting NumPy arrays of floats to integers can be done using various methods where each offers some advantages. However for simplicity and ease of use numpy.astype() becomes best choice for both 1-D and 2-D arrays.
🌐
GeeksforGeeks
geeksforgeeks.org › python › using-numpy-to-convert-array-elements-to-float-type
Using NumPy to Convert Array Elements to Float Type - GeeksforGeeks
July 15, 2025 - np.float64() is a NumPy universal function (ufunc) that converts the elements of an array into 64-bit floating-point numbers.
🌐
W3Schools
w3schools.com › python › numpy › numpy_data_types.asp
NumPy Data Types
The astype() function creates a copy of the array, and allows you to specify the data type as a parameter. The data type can be specified using a string, like 'f' for float, 'i' for integer etc. or you can use the data type directly like float ...
🌐
Educative
educative.io › answers › how-to-convert-data-types-of-arrays-using-numpy-in-python
How to convert data types of arrays using NumPy in Python
Let’s convert a float type of an array to an integer(i) type. ... Line 1: We import array from the numpy module.
Find elsewhere
🌐
Moonbooks
en.moonbooks.org › Articles › How-to-convert-a-float-array-to-an-integer-array-in-python-
How to convert a float array to an integer array in python ?
March 22, 2019 - To convert a float array to an integer array in python, a solution is to use astype, example: >>> import numpy as np >>> A = np.array((0.4, 1.6, 2.1, -3.7, 2.9)) >>> A array([ 0.4, 1.6, 2.1, -3.7, 2.9]) >>> A = A.astype(int) >>> A array([ 0, 1, 2, -3, 2]) It is also possible to round the numbers ...
🌐
Seaborn Line Plots
marsja.se › home › programming › python › how to convert a float array to an integer array in python with numpy
How to Convert a Float Array to an Integer Array in Python with NumPy
August 20, 2023 - # python convert array to int twod_int = twod.astype(int)Code language: PHP (php) Now, in the output, from both conversion examples above, we can see that the float numbers were rounded down. In some cases, we may want the float numbers to be rounded according to common practice. Therefore, in the next section, we are going to use around() method before converting. ... Now, if we want to, we can now convert the NumPy array to Pandas dataframe, as well as carry out descriptive statistics.
🌐
Finxter
blog.finxter.com › home › learn python blog › 5 best ways to convert numpy arrays to integers in python
5 Best Ways to Convert numpy Arrays to Integers in Python - Be on the Right Side of Change
February 20, 2024 - import numpy as np float_array = np.array([1.5, 2.7, 3.3]) int_array = np.around(float_array).astype(int) print(int_array) ... np.around() rounds the elements of the array to the nearest integer, which can be different from truncating as seen ...
🌐
w3resource
w3resource.com › python-exercises › numpy › python-numpy-exercise-82.php
NumPy: Convert a NumPy array of float values to a NumPy array of integer values - w3resource
August 29, 2025 - # Importing the NumPy library and aliasing it as 'np' import numpy as np # Creating a 2-dimensional array 'x' with floating-point values x = np.array([[12.0, 12.51], [2.34, 7.98], [25.23, 36.50]]) # Printing a message indicating the original array elements will be shown print("Original array elements:") # Printing the original array 'x' with its elements print(x) # Printing a message indicating the conversion of float values to integer values print("Convert float values to integer values:") # Converting the floating-point values in the array 'x' to integer values using astype(int) # Printing the array obtained after conversion print(x.astype(int))
🌐
w3resource
w3resource.com › python-exercises › numpy › python-numpy-exercise-7.php
NumPy: Array converted to a float type - w3resource
August 29, 2025 - x = np.asfarray(a): The np.asfarray() function converts the given list ‘a’ into a one-dimensional NumPy array with a floating-point data type (by default, it uses float64). In this case, the list ‘a’ contains integers, so they will be ...
🌐
Statology
statology.org › home › how to convert numpy array of floats into integers
How to Convert NumPy Array of Floats into Integers
April 3, 2025 - The following code shows how to convert a NumPy array of floats to an array of integers in which each float is rounded down to the nearest integer: #convert NumPy array of floats to array of integers (rounded down) rounded_down_integer_array = float_array.astype(int) #view array print(rounded_down_integer_array) [2 4 5 6 7 8] #view dtype of array print(rounded_down_integer_array.dtype) int64