python - Numpy 随机播放数组的子集
问题描述
我正在处理一个热编码数据的向量,并且我对随机游走进行编码,其中一个步骤是随机更改一个 ohencoded 维度,也是随机选取的。
这是代码:
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
是所有掩码的列表,每个 ohencoded 特征一个,X
是随机步行者的位置。
切入正题,我正在寻找一种更清洁、更优化的方式来进行洗牌,而无需复制、置换和向后复制。有没有办法就地改组 numpy 数组的子数组?
解决方案
推荐阅读
- .net - 使用共享文件夹跨多个开发人员的源代码管理建议
- c# - 如何使用图表创建时间表
- javascript - 如果不存在,则将数组中的值添加到另一个数组中,如果存在则从数组中过滤它
- python - 调整可变大小的图像以进行对象检测
- azure-active-directory - Microsoft Active Directory:向租户管理员询问特定权限
- java - 更新 XML 文件时缺少实体声明 - Java
- java - 重写/更改对象以更改引用而无需设置器
- javascript - 循环中的多个异步函数调用
- python - python在Mac中将Ctrl-C发送到终端
- botframework - 发送活动以响应第一个事件消息时出现 401