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.

Discussions

python - Write the digits of a number into an array - Stack Overflow
I want to calculate with seperated digits of a very long number. How can I do this in Python2.7? I thought about somehow write the digits in an array so that I can access the digits with array(x): More on stackoverflow.com
🌐 stackoverflow.com
Convert list or numpy array of single element to float in python - Stack Overflow
I have a function which can accept either a list or a numpy array. In either case, the list/array has a single element (always). I just need to return a float. So, e.g., I could receive: list_ =... More on stackoverflow.com
🌐 stackoverflow.com
Python: How do I convert an array of strings to an array of numbers? - Stack Overflow
Possible Duplicate: What is the easiest way to convert list with str into list with int? current array: ['1','-1','1'] desired array: [1,-1,1] More on stackoverflow.com
🌐 stackoverflow.com
python - Convert a number to a list of integers - Stack Overflow
Sign up to request clarification or add additional context in comments. ... Note that in Python 3.0 map will return a generator, not a list. More on stackoverflow.com
🌐 stackoverflow.com
🌐
W3Schools
w3schools.com β€Ί python β€Ί python_arrays.asp
Python Arrays
Remove List Duplicates Reverse a String Add Two Numbers Β· Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... Note: Python does not have built-in support for Arrays, but Python Lists can be used instead. Note: This page shows you how to use LISTS as ARRAYS, however, to work with arrays in Python you will have to import a library, like the NumPy library.
🌐
Programiz
programiz.com β€Ί python-programming β€Ί array
Python Array of Numeric Values
Traceback (most recent call last): File "<string>", line 3, in <module> a = arr.array('d', [1, 3.5, "Hello"]) TypeError: must be real number, not str Β· Lists are much more flexible than arrays. They can store elements of different data types including strings. And, if you need to do mathematical computation on arrays and matrices, you are much better off using something like NumPy. So, what are the uses of arrays created from the Python array module?
🌐
Python Forum
python-forum.io β€Ί thread-10876.html
Convert element of list to integer(Two dimentional array)
I'm trying to learn arrays(with numpy) in python3 but i am not able to figure out how do i convert the elements of list to integer(in my case i have two dimentional array). I've tried two solutions that i found(its mentioned in the code) but it gives...
Find elsewhere
🌐
Python
docs.python.org β€Ί 3 β€Ί library β€Ί array.html
array β€” Efficient arrays of numeric values
This module defines an object type which can compactly represent an array of basic values: characters, integers, floating-point numbers. Arrays are mutable sequence types and behave very much like lists, except that the type of objects stored in them is constrained.
🌐
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 - Write a NumPy program to cast an array of floats to integers using astype and verify that the values are truncated.
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python-convert-number-to-list-of-integers
Python - Convert Number to List of Integers - GeeksforGeeks
Let's explore some more ways and see how we can convert numbers to a list of integers. ... List comprehension provides a Pythonic way to convert a number into a list of integers.
Published Β  January 28, 2025
🌐
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 ...
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί python-arrays
Python Arrays - GeeksforGeeks
3 days ago - Note: Python does not have built-in array support in the same way that languages like C and Java do, but it provides something similar through the array module for storing elements of a single type. NumPy arrays are a part of the NumPy library, which is a tool for numerical computing in Python.
🌐
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
December 2, 2023 - 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.
🌐
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 - In this article, we will see how to convert NumPy Array of Floats into Integers. We are given a NumPy array of float-type values.
🌐
Finxter
blog.finxter.com β€Ί 5-best-ways-to-convert-an-integer-to-an-array-in-python
5 Best Ways to Convert an Integer to an Array in Python – Be on the Right Side of Change
February 18, 2024 - It can be used to iterate over a string of digits and convert each one into an integer, forming the desired array of digits. ... This code leverages list comprehension to apply the int() constructor to each character in the stringified number, resulting in an array of integers.
🌐
New York University
physics.nyu.edu β€Ί pine β€Ί pymanual β€Ί html β€Ί chap3 β€Ί chap3_arrays.html
3. Strings, Lists, Arrays, and Dictionaries β€” PyMan 0.9.31 documentation
Dictionaries are like lists, but the elements of dictionaries are accessed in a different way than for lists. The elements of lists and arrays are numbered consecutively, and to access an element of a list or an array, you simply refer to the number corresponding to its position in the sequence.