我运行了以下Python代码:
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)
期望得到这样的结果:
[[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]]
但是我得到的却是下面的错误信息:
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
你如何从一个二维列表中随机选择元素?