In [1]:
import numpy
numpy.set_printoptions(linewidth=95)
In [2]:
Filename = "matrix01.in"
In [3]:
F = open(Filename, "r")
# read one line from the file (a header)
hdr = F.next().split()
assert hdr[0].upper() == "MATRIX"
row, col = int(hdr[1]), int(hdr[2])
print("Matrix dimensions = %d x %d" % (row, col))
In [4]:
Mat = numpy.loadtxt(F)
F.close()
In [5]:
print(Mat)
In [6]:
print("Size of the matrix just read = %s" % (Mat.shape,))