I'm trying to gzip a numpy array in Python 3.6.8.
If I run this snippet twice (different interpreter sessions), I get different output:
import gzipimport numpyimport base64data = numpy.array([[1.0, 2.0, 3.0, 4.0], [5.0, 6.0, 7.0, 8.0], [9.0, 10.0, 11.0, 12.0], [13.0, 14.0, 15.0, 16.0]])compressed = base64.standard_b64encode(gzip.compress(data.data, compresslevel=9))print(compressed.decode('ascii'))
Example results (it's different every time):
H4sIAPjHiV4C/2NgAIEP9gwQ4AChOKC0AJQWgdISUFoGSitAaSUorQKl1aC0BpTWgtI6UFoPShs4AABmfqWAgAAAAA==H4sIAPrHiV4C/2NgAIEP9gwQ4AChOKC0AJQWgdISUFoGSitAaSUorQKl1aC0BpTWgtI6UFoPShs4AABmfqWAgAAAAA== ^
Running it in a loop (so the same interpreter session),it gives the same result each time
for _ in range(1000): assert compressed == base64.standard_b64encode(gzip.compress(data.data, compresslevel=9))
How can I get the same result each time? (Preferably without external libraries.)