in mnist-vscode-docs-sample/utils.py [0:0]
def load_data(filename, label = False):
with gzip.open(filename) as gz:
magic_number = struct.unpack('I', gz.read(4))
n_items = struct.unpack('>I', gz.read(4))
if not label:
n_rows = struct.unpack('>I', gz.read(4))[0]
n_cols = struct.unpack('>I', gz.read(4))[0]
res = np.frombuffer(gz.read(n_items[0] * n_rows * n_cols), dtype = np.uint8)
res = res.reshape(n_items[0], n_rows * n_cols)
else:
res = np.frombuffer(gz.read(n_items[0]), dtype = np.uint8)
res = res.reshape(n_items[0], 1)
return res