summaryrefslogtreecommitdiffstats
path: root/demos/data/binary_save.py
blob: 3fb216232d66fdc276beb279c70b50e1df2dd822 (plain)
1
2
3
4
5
6
7
8
9
10
11
import numpy as np
outfile = open('my_file.bin', 'wb')  # Open a file for binary write
outfile.write(im)  # Write it
outfile.flush()  # Optional but a good idea
outfile.close()

# Define width and height
w, h = 256, 256
# Read file using numpy "fromfile()"
with open('my_file.bin', mode='rb') as f:
    d = np.fromfile(f,dtype=np.float32,count=w*h).reshape(h,w)