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

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


1. numpy.random.shuffle()

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

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


2. numpy.random.permutation()

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

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

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

相关文章
相关标签/搜索