Last active
October 2, 2020 17:25
-
-
Save njvack/ebc754ea47dda6eb2e2c5ad6f7ac47d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Generates an array blocks * block_len long, containing 1 and 2. | |
It's shuffled such that there can never be more than block_len | |
consecutive repetitions of either value. | |
""" | |
import numpy as np | |
blocks = 100 | |
block_len = 8 | |
groupnums = (np.arange(blocks * block_len) % 2) + 1 | |
blocked = groupnums.reshape(blocks, block_len) | |
np.apply_along_axis(np.random.shuffle, 1, blocked) | |
groups = blocked.reshape(blocks * block_len) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment