栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何取消数据混洗?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何取消数据混洗?

根据您对的选择,不一定有可能

f
。如果
f
是可逆的,并且您跟踪行的混排方式,即使效率不高,也有可能。sklearn.utils随机播放方法不会“跟踪”矩阵的随机播放方式。您可能需要自己动手。要生成随机随机播放,请生成的随机排列
range(len(A))
,然后以该顺序迭代交换行。要检索原始矩阵,您可以反转排列。这将允许您针对某些选择
f
(例如矩阵加法)恢复C。

(编辑,OP请求了其他信息)

这对我有用,但是可能有更有效的方法:

import numpy as npdef shuffle(A,axis=0,permutation=None):    A = np.swapaxes(A,0,axis)    if permutation is None:        permutation = np.random.permutation(len(A))    temp = np.copy(A[permutation[0]])    for i in range(len(A)-1):        A[permutation[i]] = A[permutation[i+1]]    A[permutation[-1]] = temp    A = np.swapaxes(A,0,axis)    return A, permutationA = np.array([[1,2],[3,4],[5,6],[7,8]])print AB, p = shuffle(A) #NOTE: shuffle is in place, so A is the same object as B!!!!print "shuffle A"print BD, _ = shuffle(B,permutation=p[::-1])print "unshuffle B to get A"print DB = np.copy(B)C = A+Bprint "A+B"print CA_s, p = shuffle(A)B_s, _ = shuffle(B, permutation = p)C_s = A_s + B_sprint "shuffle A and B, then add"print C_sprint "unshuffle that to get the original sum"CC, _ = shuffle(C_s, permutation=p[::-1])print CC


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/661441.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号