根据您对的选择,不一定有可能
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



