Python: converting tuple into 2D array
10,921
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]]
Comments
-
eudaimonia almost 2 years
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?