Skip to content

Instantly share code, notes, and snippets.

@nbertagnolli
Last active March 1, 2020 22:49
Show Gist options
  • Save nbertagnolli/78850b0e501129e31c83de0414837245 to your computer and use it in GitHub Desktop.
Save nbertagnolli/78850b0e501129e31c83de0414837245 to your computer and use it in GitHub Desktop.
Generates a tuple containing a list of ones and a list of binary even numbers
def generate_even_data(max_int: int, batch_size: int=16) -> Tuple[List[int], List[List[int]]]:
# Get the number of binary places needed to represent the maximum number
max_length = int(math.log(max_int, 2))
# Sample batch_size number of integers in range 0-max_int
sampled_integers = np.random.randint(0, int(max_int / 2), batch_size)
# create a list of labels all ones because all numbers are even
labels = [1] * batch_size
# Generate a list of binary numbers for training.
data = [create_binary_list_from_int(int(x * 2)) for x in sampled_integers]
data = [([0] * (max_length - len(x))) + x for x in data]
return labels, data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment