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),再打乱顺序

  • 相关阅读:
    自动化部署功
    docker 安装
    批量操作
    centos7 内核升级
    centos 6.5 升级 内核
    如何进行再linux 下查看 java程序的堆栈信息
    binlog 日志恢复以及操作
    java 中 Integer 比较 问题
    docker 使用
    soucetree 安装
  • 原文地址:https://www.cnblogs.com/dinghongkai/p/11422744.html
Copyright © 2011-2022 走看看