Numpy洗牌数组的子集

2024-07-07 09:17:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我在处理一个热编码数据的向量,我在编码一个随机游走,其中的一个步骤是随机改变一个编码的维度,随机选取。你知道吗

代码如下:

MASK = random.choice(MASKS) #picks one of the ohencoded features (its mask)
SUB = X[MASK]
np.random.shuffle(SUB) #changes the ohencoded dimension by shuffling the 0s and single 1
X[MASK] = SUB #propagates back the new permutation

其中MASKS是所有掩码的列表,每个编码特征一个,X是随机游走器位置。你知道吗

切入正题,我正在寻找一种更干净、更优化的方法,在不必复制、排列和向后复制的情况下进行洗牌。有没有一种方法可以将numpy阵列的子阵列洗牌?你知道吗


Tags: the方法代码编码步骤maskrandomone