code: def mnist_extract_labels(filename, num_images):
    
    print('Extracting', filename)
    with gzip.open(filename) as bytestream:
      bytestream.read(8)
      buf = bytestream.read(1 * num_images)
      labels = np.frombuffer(buf, dtype=np.uint8)
    # Convert to dense 1-hot representation.
    return (np.arange(10) == labels[:, None]).astype(np.float32)
docs: Extract the labels into a 1-hot matrix [image index, label index].