I have a text file which contains matrix of N * M dimensions.
For example the input.txt file contains the following:
You should not write your csv parser, consider the csv module when reading such files and use the with statement to close after reading:
csv
with
import csv with open('input.txt') ad f: data = [map(int, row) for row in csv.reader(f)]