Merge numpy array to single int

Viewed 957

How can a numpy array like this:

[10, 22, 37, 45]

be converted to a single int32 number like this:

10223745

2 Answers

This could work:

>>> int(''.join(map(str, [10, 22, 37, 45])))
10223745

Basically you use map(str, ...) to convert that array of integers to string, then ''.join to concatenate each of those strings, and finally int to convert the whole thing to an integer.

s = ""
for i in num_arr:
      s += str(i)

print(int(i))
Related