Created
May 22, 2024 20:42
-
-
Save Eeman1113/7a20c7b67315eac6bfde1666845ae675 to your computer and use it in GitHub Desktop.
This file contains 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
def generate_random_list(shape): | |
""" | |
Generate a list with random numbers and shape 'shape' | |
[4, 2] --> [[rand1, rand2], [rand3, rand4], [rand5, rand6], [rand7, rand8]] | |
""" | |
if len(shape) == 0: | |
return [] | |
else: | |
inner_shape = shape[1:] | |
if len(inner_shape) == 0: | |
return [random.uniform(-1, 1) for _ in range(shape[0])] | |
else: | |
return [generate_random_list(inner_shape) for _ in range(shape[0])] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment