【code】
import numpy as np# 创建随机交换的索引permutation = list(np.random.permutation(3))# 创建矩阵X,YX = np.array([[0, 1, 2], [0, 1, 2], [0, 1, 2]])Y = np.array([[0, 1, 2]])# 交换顺序shuffled_X = X[:, permutation]shuffled_Y = Y[:, permutation]# 输出print("permutation:")print(permutation)print("X:")print(X)print("Y:")print(Y)print("shuffled_X:")print(shuffled_X)print("shuffled_Y:")print(shuffled_Y)
【result】
permutation:[1, 2, 0] X:[[0 1 2] [0 1 2] [0 1 2]] Y:[[0 1 2]] shuffled_X:[[1 2 0] [1 2 0] [1 2 0]] shuffled_Y:[[1 2 0]]