I want to convert tuple like
t = [(4,10),(9,7),(11,2),(2,2)]
into 2D array like:
a = [[4,10],[9,7],[11,2],[2,2]]
I tried
a = []
for i in t:
a.append(np.asarray(i))
print a
is there any easier way?
Use a list comprehension as follows:
>>> t = [(4,10),(9,7),(11,2),(2,2)]
>>> [list(item) for item in t]
[[4, 10], [9, 7], [11, 2], [2, 2]]
a = map(list, t)Py2 ,mapchanges in Py3 and you needa = list(map(list, t))for Py3map()result to a list.