我有一个中等大的np
数组(但将来可能会变得更大):
import numpy as np
x = np.arange(100_000).reshape((10_000,10))
我需要迭代地 Select 一个随机样本(行),确保我永远不会 Select 同一样本两次.目前我正在做
rng = np.random.default_rng(seed=42)
indices = list(range(len(x)))
for _ in range(1000):
i = rng.choice(indices)
## do something with x[i]
indices.remove(i)
然而,我读到remove
相当慢.有更好的方法来跟踪我已经使用的指数吗?