• numpy.random.shuffle()与numpy.random.permutation()的区别


    参考API:https://docs.scipy.org/doc/numpy/reference/routines.random.html


    1. numpy.random.shuffle()

      API中关于该函数是这样描述的:

    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.

      也就是说,numpy.random,shuffle(x)是进行原地洗牌,直接改变x的值,而无返回值。对于多维度的array来说,只对第一维进行洗牌,比如一个 $ 3 imes 3 $ 的array,只对行之间进行洗牌,而行内内容保持不变。
      例子:


    2. numpy.random.permutation()

      API中关于该函数是这样描述的:

    Randomly permute a sequence, or return a permuted range.
    If x is a multi-dimensional array, it is only shuffled along its first index.

      也就是说,numpy.random,permutation(x)是返回一个被洗牌过的array,而x不变。对于多维度的array来说,只对第一维进行洗牌,比如一个 $ 3 imes 3 $ 的array,只对行之间进行洗牌,而行内内容保持不变。
      例子:

  • 相关阅读:
    交换实验
    路由引入和控制
    ISIS
    BGP联盟
    BGP2
    bgp
    Linux日常总结
    配置本地yum源方法
    达梦数据库常见问题-安装
    达梦数据库常见问题-安装
  • 原文地址:https://www.cnblogs.com/lliuye/p/9440839.html
Copyright © 2020-2023  润新知