Possible Duplicate:
How can I turn a list into an array in python?
How can I turn a list such as:
<
Based on the answer from Fred Foo, if you're already using numpy
, you may use reshape to get a 2d array without copying the data:
import numpy
new_list = numpy.array(data_list).reshape(-1, 3)
new_list = [data_list[x:x+3] for x in range(0, len(data_list) - 2, 3)]
List comprehensions for the win :)