def fast_random_bool(shape):
    n = np.prod(shape)
nb = -(-n // 8)
b = np.fromstring(np.random.bytes(nb), np.uint8, nb)
Memory-efficient way to generate a large numpy array containing random boolean values