For those one liner:
>>> data = [0, 2, 7, 6, 3, 1, 4, 5] >>> col = 4 # just grab the number of columns here >>> [data[i:i+col] for i in range(0, len(data), col)] [[0, 2, 7, 6],[3, 1, 4, 5]] >>> # for pretty print, use either np.array or np.asmatrix >>> np.array([data[i:i+col] for i in range(0, len(data), col)]) array([[0, 2, 7, 6], [3, 1, 4, 5]])
B.Mr.W.
source share