来自:https://blog.csdn.net/brucewong0516/article/details/79012233

将数组打乱随机排列 两种方法:

  1. np.random.shuffle(x):在原数组上进行,改变自身序列,无返回值。
  2. np.random.permutation(x):不在原数组上进行,返回新的数组,不改变自身数组。

1. np.random.shuffle(x)

(1)、一维数组

import numpy as np

arr = np.arange(10)
print(arr) np.random.shuffle(arr)
print(arr)

(2)、对多维数组进行打乱排列时,默认是列维度。

arr = np.arange(12).reshape(3,4)
print(arr) np.random.shuffle(arr)
print(arr)

2. np.random.permutation(x)

(1)、可直接生成一个随机排列的数组

np.random.permutation(10)

(2)、一维数组

np.random.permutation([1, 4, 9, 12, 15])

(3)、多维数组

arr = np.arange(9).reshape((3, 3))
print(arr) arr2 = np.random.permutation(arr)
print(arr)
print(arr2)

3. 区别

从代码可以看出,np.random.shuffle(x)改变自身数组,np.random.permutation(x)不改变自身数组。

np.random.shuffle(x)与np.random.permutation(x)的更多相关文章

  1. NP:建立可视化输入的二次函数数据点集np.linspace+np.random.shuffle+np.random.normal

    import numpy as np import matplotlib.pyplot as plt def fix_seed(seed=1): #重复观看一样东西 # reproducible np ...

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

    参考API:https://docs.scipy.org/doc/numpy/reference/routines.random.html 1. numpy.random.shuffle()   AP ...

  3. numpy.random.shuffle(x)的用法

    numpy.random.shuffle(x) Modify a sequence in-place by shuffling its contents. Parameters: x : array_ ...

  4. 9. 获得图片路径,构造出训练集和验证集,同时构造出相同人脸和不同人脸的测试集,将结果存储为.csv格式 1.random.shuffle(数据清洗) 2.random.sample(从数据集中随机选取2个数据) 3. random.choice(从数据集中抽取一个数据) 4.pickle.dump(将数据集写成.pkl数据)

    1. random.shuffle(dataset) 对数据进行清洗操作 参数说明:dataset表示输入的数据 2.random.sample(dataset, 2) 从dataset数据集中选取2 ...

  5. python用random产生验证码,以及random的一些其他用法

    产生随机验证码函数 import random def get_code(): code = '' for i in range(5): num = str(random.randrange(10)) ...

  6. np.random.shuffle(x)的用法

    此函数主要是通过改变序列的内容来修改序列的位置.此函数只沿多维数组的第一个轴移动数组.子数组的顺序已更改,但其内容保持不变. 参数 x:即将被打乱顺序的list 返回值 无

  7. reservoir sampling / random shuffle

    randomly choose a sample of k items from a list S containing n elements, the algorithm may be online ...

  8. 洗牌利器——random.shuffle()函数

    random.shuffle()是一个非常实用但是又非常容易被忽略的函数,shuffle在英语里是"洗牌"的意思,该函数非常形象地模拟了洗牌的过程,即: random.shuffl ...

  9. zenefits oa - random(5) to generate a random(7)

    If given a function that generates a random number from 1 to 5, how do you use this function to gene ...

随机推荐

  1. urlencode编/解码

    from urllib.parse import urlencode, quote, unquote # urlencode方法参数是字典 body = { "content": ...

  2. hadoop的权限控制

    HDFS支持权限控制,但支持较弱.HDFS的设计是基于POSIX模型的,支持按用户.用户组.其他用户的读写执行控制权限.在linux命令行下,可以使用下面的命令修改文件的权限.文件所有者,文件所属组: ...

  3. Codeforces 985 最短水桶分配 沙堆构造 贪心单调对列

    A B /* Huyyt */ #include <bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define mkp(a, ...

  4. java高并发实战Netty+协程(Fiber)|系列1(续)|事件驱动模式和零拷贝

    上次讲到事件驱动模式,今天我们来好好分析下netty的事件模式的几个类型. 先从NIO讲起, JAVA NIO方面Selector给Reactor模式提供了基础,Netty结合Selector和Rea ...

  5. Excel筛选操作

    Excel的筛选操作如下: 选中指定列: 点击"开始"中的"排序和筛选" 点击如下小三角即可按条件进行筛选

  6. python的flex服务端数据接口开发

    python的flex服务端数据接口开发 python 如果给flex提供服务端,需要提供一个网关和一个可供客户端(flex)调用的类.这方面我更加推荐用twisted来写这个网关,因为twisted ...

  7. pyqt5--动画

    动画类别继承结构图 天子骄龙

  8. 移动端ios和安卓input问题

    在钉钉开发微应用的时候. 安卓和苹果输入input框的时候.失去焦点和获取焦点会有明显的上下跳动 因此我用绝对定位把位置固定在一个地方.就不会有跳动

  9. Leaflet使用vector tiles样式设置

    //point style var myIcon = L.icon({ iconUrl: 'css/images/dian.svg', // shadowUrl: 'css/images/leaf-s ...

  10. STL::allocator rebind

    阅读侯捷的STL源码剖析时,发现在allocator类的代码中有这样一个struct template<class T> class allocator { ... template< ...