Reputation: 945
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])))
Upvotes: 1
Views: 343
Reputation: 30268
A slightly more mathematical way:
>>> [sum(n*10**i for i, n in enumerate(reversed(x))) for x in arr]
[234, 123, 345]
Upvotes: 0
Reputation: 153
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
Upvotes: 0