2020-04-09 21:13:38 +02:00
|
|
|
import numpy as np
|
2020-04-13 15:59:34 +02:00
|
|
|
import zlib
|
2020-04-09 21:13:38 +02:00
|
|
|
|
|
|
|
def save(data, fname, dtype=None):
|
|
|
|
if dtype is not None:
|
|
|
|
data = data.astype(dtype)
|
|
|
|
|
2020-04-13 15:59:34 +02:00
|
|
|
bin_data = data.tobytes()
|
|
|
|
bin_data_comp = zlib.compress(bin_data, 9)
|
|
|
|
if len(bin_data_comp) < len(bin_data):
|
|
|
|
bin_data = bin_data_comp
|
2020-04-09 21:13:38 +02:00
|
|
|
with open(fname, 'wb') as f:
|
2020-04-13 15:59:34 +02:00
|
|
|
f.write(bin_data)
|