zoukankan      html  css  js  c++  java
  • Python中对矩阵的洗牌操作

    【code】

    import numpy as np
    
    # 创建随机交换的索引
    permutation = list(np.random.permutation(3))
    
    # 创建矩阵X,Y
    X = 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]]
  • 相关阅读:
    UVa 1605
    UVa 120
    UVa 10384
    UVa 11694
    UVa 11846
    常用小函数
    【DP】:CF #319 (Div. 2) B. Modulo Sum
    类的无参方法
    类和对象
    七言
  • 原文地址:https://www.cnblogs.com/hezhiyao/p/8065950.html
Copyright © 2011-2022 走看看