我有一个像这样的数组,
[[ 5.80084178e-05 1.20779787e-02 -2.65970238e-02]
[ -1.36810406e-02 6.85722519e-02 -2.60280724e-01]
[ 4.21996519e-01 -1.43644036e-01 2.12904690e-01]
[ 3.03098198e-02 1.50170659e-02 -1.09683402e-01]
[ -1.50776089e-03 7.22369575e-03 -3.71181228e-02]
[ -3.04448275e-01 -3.66987035e-01 1.44618682e-01]
[ -1.46744916e-01 3.47112167e-01 3.09550267e-01]
[ 1.16567762e-03 1.72858807e-02 -9.39297514e-02]
[ 1.25896836e-04 1.61310167e-02 -6.00253128e-02]
[ 1.65062798e-02 1.96933143e-02 -4.26540031e-02]
[ -3.78020965e-03 7.51770012e-03 -3.67852984e-02]]
我想从这些中选择任意n
(例如:1000)随机行数,因此输出将是:
[[ -1.36810406e-02 1.72858807e-02 -4.26540031e-02]
[ 1.16567762e-03 7.51770012e-03 -2.60280724e-01]
....
....
.... ]]
即。通过从每列中随机选择值来生成输出行。来自11x3以上阵列的可能样本数量为11 * 11 * 11.
有人可以帮我在python中执行此操作吗?
答案 0 :(得分:0)
如果上面的初始11x3数组是'A',
import random
arr=np.zeros(shape=(1000,5))
for k in range(0,1000) :
B=[]
for i in range(0,3):
B.append(random.choice(A.transpose()[i]))
arr[k]=B
简单地说,'arr'会给我我想要的东西。但是,对于这个没有更好的现有算法吗?