1

This is the closest I could come up with: Convert list of ints to one number?

Basically, I have an list of lists of integers:

arr = [[2,3,4], [1,2,3], [3,4,5]]

How do I get this so that it's: [234, 123, 345] as integers?

Edit: I would like to vectorize this code that I can use:

result = np.zeros(len(arr))
for i in range(len(arr)):
    result[i] = int(''.join(map(str, arr[i])))
Community
  • 1
  • 1
user1883614
  • 905
  • 3
  • 16
  • 30

3 Answers3

4
[int(''.join(map(str, x))) for x in arr]
# [234, 123, 345]
Psidom
  • 209,562
  • 33
  • 339
  • 356
0
arr = [[2,3,4], [1,2,3], [3,4,5]]
arr2 = []
for x in arr:
    z = ""
    for y in x:
        z = z + str(y)
    arr2.append(int(z))
#the results are now in arr2
print arr2
ANVGJSENGRDG
  • 153
  • 1
  • 8
0

A slightly more mathematical way:

>>> [sum(n*10**i for i, n in enumerate(reversed(x))) for x in arr]
[234, 123, 345]
AChampion
  • 29,683
  • 4
  • 59
  • 75