Generating an unique seed for a given filename
When creating large simulations, you may sometimes create unique identifiers for each of it. This is useful to cache intermediate results for instance. This is the main function of hashes. We will here create a simple one-liner function to generate one.
In [1]:
filename = 'https://raw.githubusercontent.com/bicv/SLIP/master/database/serre07_targets/B_N107001.jpg'
print ('filename=', filename)
In [2]:
import os
import hashlib
hash_str = hashlib.sha224(filename.encode('utf-8')).hexdigest()
print('hash_str=', hash_str)
In [3]:
filename = 'https://raw.githubusercontent.com/bicv/SLIP/master/database/serre07_targets/B_N107002.jpg'
print ('filename=', filename)
print('hash_str=', hashlib.sha224(filename.encode('utf-8')).hexdigest())
Done! This gives a simple one-liner to associate a filename to a (most probably) hash.
dependencies¶
In [4]:
%load_ext watermark
%watermark
In [5]:
%load_ext version_information
%version_information numpy, hashlib
Out[5]: