博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
numpy.random.shuffle()与numpy.random.permutation()的区别
阅读量:4622 次
发布时间:2019-06-09

本文共 763 字,大约阅读时间需要 2 分钟。

参考API:


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.

1238724-20180808091826344-373138427.jpg

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

  例子:
1238724-20180808091855503-417305788.jpg


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.

1238724-20180808092315908-1942554122.jpg

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

  例子:
1238724-20180808092507172-1204995748.jpg

转载于:https://www.cnblogs.com/lliuye/p/9440839.html

你可能感兴趣的文章
mysql六:数据备份、pymysql模块
查看>>
docker-compose 案例
查看>>
数据结构之哈夫曼树
查看>>
ios 图片裁剪修改尺寸的方法总结
查看>>
待看数据类型
查看>>
DELPHI中 screen.Cursor:=crhourglass; adoQuery.close; adoquery.Open; screen.Cursor:=crdefault;啥意思...
查看>>
JavaScript 判断变量是否为数组Array的方法
查看>>
BZOJ 1602 USACO 2008 Oct. 牧场行走
查看>>
activiti 核心API
查看>>
获取DataTable前几条数据
查看>>
面试题
查看>>
“Dynamic Web Module 3.0 requires Java 1.6 or newer.”错误 (转别人)
查看>>
20145313张雪纯《信息安全系统设计基础》第9周学习总结
查看>>
CC_CALLBACK原理及应用
查看>>
常用的input样式美化。
查看>>
SQL Server 错误:924 解决方法
查看>>
win7 下 vim字体默认设置
查看>>
leetCode 65.Valid Number (有效数字)
查看>>
hdu 1754 I Hate It 线段树 点改动
查看>>
Latex - test
查看>>