To recreate the shape, you need to save the shape when you save the file.
Try:
import numpy as np
import re
result=np.array([[1.,0.,0.,0.00375,-0.01072,-0.,-1000.,],
[2.,3.,4.,0.,-0.004,750.,0.],
[3.,3.,0.,0.,0.,-750.,1000.]])
with open('/tmp/test', 'w') as fout:
fout.write(u'#'+'\t'.join(str(e) for e in result.shape)+'\n')
result.tofile(fout)
with open('/tmp/test', 'rb') as f:
line=f.readline().decode('ascii')
if line.startswith('#'):
shape=tuple(map(int, re.findall(r'(\d+)', line)))
else:
raise IOError('Failed to find shape in file')
result2=np.fromfile(f)
result3=result2.reshape(shape)
print(np.array_equal(result, result2))
# False
print(np.array_equal(result, result3))
# True
You can save the shape in some form in the file in oder to recreate the same shape. Make sure you do not forget the data at the beginning of the file however, since unlike np.loadtxt, lines starting with #
are still considered data.