Here is the code that i am trying to enforce with real example
#Create a dtype to represent the header.
header_dtype = dtype([('rows', int32), ('cols', int32)])
# Create a memory mapped array using this dtype. Note the shape is empty.
header = memmap(file_name, mode='r', dtype=header_dtype, shape=())
# Read the row and column sizes from using this structured array.
rows = header['rows']
cols = header['cols']
# Create a memory map to the data segment, using rows, cols for shape
# information and the header size to determine the correct offset.
data = memmap(file_name, mode='r+', dtype=float64,shape=(rows, cols),
offset=header_dtype.itemsize)
The file format that i want to read using memmap is

I am wondering what is going wrong when i try to read the following file named matrix.dat
4 4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
I am doing the following in python (Enthought's canopy editor)
header_dtype = dtype([('rows',int),('cols',int)])
header=memmap('matrix.dat',mode='r',dtype=header_dtype,shape=())
rows = header['rows']
cols=header['cols']
print header
(221519924, 840970506)
print rows cols
221519924, 840970506
Why i am not getting 4, 4? How do i change the file matrix.dat shown above to read the data correctly?
numpy.loadtxtif better suited for text files.