I have a text file which contains matrix of N * M dimensions.
For example the input.txt file contains the following:
You can simply use numpy.loadtxt. Easy to use, and you can also specify your delimiter, datatypes etc.
specifically, all you need to do is this:
import numpy as np
input = np.loadtxt("input.txt", dtype='i', delimiter=',')
print(input)
And the output would be:
[[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0 0]
[0 0 2 1 0 2 0 0 0 0]
[0 0 2 1 1 2 2 0 0 1]
[0 0 1 2 2 1 1 0 0 2]
[1 0 1 1 1 2 1 0 2 1]]