参考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 times 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 times 3 $ 的array,只对行之间进行洗牌,而行内内容保持不变。
  例子:

内容来源于网络如有侵权请私信删除
你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!