来自: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. 如何写一个 Burp 插件

    Burp 是 Web 安全测试中不可或缺的神器.每一个师傅的电脑里面应该都有一个 Burp.同时 Burp 和很多其他神器一样,它也支持插件.但是目前总体来说网上 Burp 插件开发的资料不是特别特别 ...

  2. ucore Lab2 实验笔记

    ucore Lab2 lab 2 直接执行make qemu-nox会显示 assert 失败: kernel panic at kern/mm/default_pmm.c:277: assertio ...

  3. 微软推出全新的Windows终端应用程序

    微软正推出一款名为Windows Terminal的新命令行应用程序.它被设计为访问PowerShell,cmd.exe和Windows子系统Linux(WSL)等环境的中心位置.微软正在为想要调整终 ...

  4. 2>&1的含义解释

    某次想将adb的help信息保存起来 F:\android系统\AndroidTool_Release_v2.\bin>adb >help.txt 结果 F:\android系统\Andr ...

  5. java面试(集合类)03

    1.Collection 和 Collections 有什么区别? Collection 是一个集合接口,它提供了对集合对象进行基本操作的通用接口方法,所有集合都是它的子类,比如 List.Set 等 ...

  6. PHP判断邮箱地址是否合法的正则表达式

    PHP判断邮箱地址是否合法的正则表达式: function checkEmail($inAddress){ return (preg_match("/^([a-zA-Z0-9_-])+@([ ...

  7. web框架-(七)Django补充---models进阶操作及modelform操作

    通过之前的课程我们可以对于Django的models进行简单的操作,今天了解下进阶操作和modelform: 1. Models进阶操作 1.1 字段操作 AutoField(Field) - int ...

  8. [易学易懂系列|rustlang语言|零基础|快速入门|(11)|Structs结构体]

    [易学易懂系列|rustlang语言|零基础|快速入门|(11)] 有意思的基础知识 Structs 我们今天来看看数据结构:structs. 简单来说,structs,就是用来封装相关数据的一种数据 ...

  9. Codeforces Round #569 (Div. 2) C. Valeriy and Deque

    链接: https://codeforces.com/contest/1180/problem/C 题意: Recently, on the course of algorithms and data ...

  10. 一张图解释Linux文件系统中硬链接和软链接的区别

    如图所示,硬链接与原始文件共用一个inode,但inode是不跨文件系统的(Ext3.Ext4),每个文件系统都有自己的inode列表.因此,硬链接是没办法跨文件系统的 而软链接不同,软链接相当于重新 ...