Python reshape list to ndim array

You can think of reshaping that the new shape is filled row by row (last dimension varies fastest) from the flattened original list/array. An easy solution is to shape the list into a (100, 28) array and then transpose it: Update regarding the updated example:

load csv into 2D matrix with numpy for plotting

Pure numpy Check out the loadtxt documentation. You can also use python’s csv module: You will have to convert it to your favorite numeric type. I guess you can write the whole thing in one line: result = numpy.array(list(csv.reader(open(“test.csv”, “rb”), delimiter=”,”))).astype(“float”) Added Hint: You could also use pandas.io.parsers.read_csv and get the associated numpy array which can be faster.