zoukankan      html  css  js  c++  java
  • Numpy 随机序列 shuffle & permutation

    1. numpy.random.shuffle(x)

    Modify a sequence in-place by shuffling its contents.
    
    This function only shuffles the array along the first axis of a multi-dimensional array. The order of sub-arrays is changed but their contents remains the same.
    
    Parameters:	
    x : array_like. The array or list to be shuffled.
    
    Returns: None

    注意:

    • 无返回值,改变原有 array
    • 对于多维 array,只 shuffle 第一维

    2. numpy.random.permutation(x) 

    Randomly permute a sequence, or return a permuted range.
    
    If x is a multi-dimensional array, it is only shuffled along its first index.
    
    Parameters:	
    x : int or array_like
    
    If x is an integer, randomly permute np.arange(x). If x is an array, make a copy and shuffle the elements randomly.
    
    Returns:	
    out : ndarray
    
    Permuted sequence or array range.

    注意:

    • 跟 shuffle 的区别
      • 有返回值
      • 且不改变原来的 array,会生成一个新的 array
    • x 为整型时,先将 x 变成 array: np.arange(x),再打乱顺序

  • 相关阅读:
    [CF1342D] Multiple Testcases
    [CF448D] Multiplication Table
    [CF459C] Pashmak and Buses
    [CF766E] Mahmoud and a xor trip
    [CF35E] Parade
    [CF15C] Industrial Nim
    [CF9D] How many trees?
    [CF19B] Checkout Assistant
    [CF22D] Segments
    [CF21D] Traveling Graph
  • 原文地址:https://www.cnblogs.com/dinghongkai/p/11422744.html
Copyright © 2011-2022 走看看