I ran the following python code:
import numpy as np
a_list = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 1, 2]]
np.random.choice(a_list, size=20,
replace=True)
expecting a result like this:
[[7, 8, 9], [1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 1, 2], [1, 2, 3], [1, 2, 3], [10, 1, 2], [1, 2, 3], [7, 8, 9], [1, 2, 3], [1, 2, 3], [10, 1, 2], [4, 5, 6], [4, 5, 6], [10, 1, 2], [10, 1, 2], [7, 8, 9], [1, 2, 3], [7, 8, 9]]
but what I got instead was the error message below:
ValueError Traceback (most recent call last)
<ipython-input-80-c11957aca587> in <module>()
2 a_list = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 1, 2]]
3 np.random.choice(a_list, size=20,
----> 4 replace=True)
mtrand.pyx in mtrand.RandomState.choice()
ValueError: a must be 1-dimensional
How do you randomly choose from a 2-dimensional list?