From 02393381dfadf46ee7a83cc9df9a9c3fbe16606a Mon Sep 17 00:00:00 2001 From: kris Date: Tue, 12 Jan 2021 22:01:29 +0000 Subject: [PATCH] Write out mmapp'ed numpy array instead of pickling --- precompute_distance.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/precompute_distance.py b/precompute_distance.py index 5f3b7f4..243d3d2 100644 --- a/precompute_distance.py +++ b/precompute_distance.py @@ -1,6 +1,3 @@ -import bz2 -import pickle - import dither import colour.difference import numpy as np @@ -28,11 +25,10 @@ def nearest_colours(): diffs[:, i] = colour.difference.delta_E_CIE2000(all_lab, palette_lab) norm = np.max(diffs) - print(norm) return (diffs / norm * 255).astype(np.uint8) - #return diffs n = nearest_colours() -with bz2.open("nearest2.pickle.bz2", "wb") as f: - pickle.dump(n, f) +out = np.memmap(filename="distances.npy", mode="w+", dtype=np.uint8, + shape=n.shape) +out[:] = n[:]