def readslice(inputfilename, ndim):
    shape = ndim, ndim, ndim
fd = open(fname, 'rb')
data = np.fromfile(file=fd, dtype=np.double).reshape(shape)
how to read an outputted fortran binary NxNxN matrix into Python