Try something like that:
In [53]: l = [0,1,2,3]
In [54]: def to_matrix(l, n):
...: return [l[i:i+n] for i in xrange(0, len(l), n)]
In [55]: to_matrix(l,2)
Out[55]: [[0, 1], [2, 3]]
More Related Contents:
- Transpose/Unzip Function (inverse of zip)?
- Difference between numpy.array shape (R, 1) and (R,)
- What are the differences between numpy arrays and matrices? Which one should I use?
- Very large matrices using Python and NumPy
- numpy matrix vector multiplication [duplicate]
- Get all the diagonals in a matrix/list of lists in Python
- how does multiplication differ for NumPy Matrix vs Array classes?
- Pretty print 2D list?
- Bin elements per row – Vectorized 2D Bincount for NumPy
- Convolve2d just by using Numpy
- Sum of list of lists; returns sum list
- How can I plot a confusion matrix? [duplicate]
- Convert a 1D array to a 2D array in numpy
- numpy get index where value is true
- How to input matrix (2D list) in Python?
- How do I calculate a word-word co-occurrence matrix with sklearn?
- Efficiently Calculating a Euclidean Distance Matrix Using Numpy
- Block tridiagonal matrix python
- how to perform max/mean pooling on a 2d array using numpy
- How to generalize fast matrix multiplication on GPU using numba
- Why does numpy.linalg.solve() offer more precise matrix inversions than numpy.linalg.inv()?
- NumPy array/matrix of mixed types
- How to convert a column or row matrix to a diagonal matrix in Python?
- Is there a standard solution for Gauss elimination in Python?
- How to find linearly independent rows from a matrix
- Convert row vector to column vector in NumPy
- Numpy select rows based on condition
- How to find the pairwise differences between rows of two very large matrices using numpy?
- Is MATLAB faster than Python?
- A numpy array unexpectedly changes when changing another one despite being separate