3

How can a numpy array like this:

[10, 22, 37, 45]

be converted to a single int32 number like this:

10223745

3
  • sum(arr.astype(str))? Commented Dec 14, 2020 at 17:02
  • @Arandomcoder, which concatenation do you have in mind? Array, list, string? Commented Dec 14, 2020 at 18:19
  • Are you really dealing with an array? or is this just a list of numbers? Are the numbers all 2 digits? Commented Dec 14, 2020 at 18:20

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

Comments

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

print(int(i))

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.