当前位置:网站首页>解析numpy.random.get_state()和numpy.random.set_state()
解析numpy.random.get_state()和numpy.random.set_state()
2022-07-22 05:07:00 【Wanderer001】
- 解析numpy.random.get_state()和numpy.random.set_state()
- get_state():可理解为设定状态,记录下数组被打乱的操作
- set_state():接收get_state()返回的值,并进行同样的操作
- 一般结合random.shuffle()函数使用
- 将实例与标签两个数组同时打乱,但打乱后,实例与标签任然是一一对应的关系
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 4 15:30:47 2018
@author: muli
"""
import numpy as np
#random.getstate()
#返回对象捕获发生器的当前内部状态。这个对象可以传递给setstate()来恢复状态
#random.setstate(state)
#状态应该已经从以前的调用中获得getstate(),
#以及setstate()恢复发生器的getstate()被调用的时候的内部状态。
a = np.arange(10)
print("a:")
print(a)
b=['A','B','C','D','E','F','G','H','I','J']
print("b:")
print(b)
print("----------------------------")
state=np.random.get_state()
np.random.shuffle(a)
print(a)
np.random.set_state(state)
np.random.shuffle(b)
print(b)
结果为:
a:
[0 1 2 3 4 5 6 7 8 9]
b:
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']
----------------------------
[8 3 4 1 6 2 9 5 7 0]
['I', 'D', 'E', 'B', 'G', 'C', 'J', 'F', 'H', 'A']
边栏推荐
- Complex network modeling (network robustness)
- Concis组件库 | 暗黑模式设计
- 解析参与机器人教育竞赛的热潮
- Binary tree OJ question, IO question
- C language program practice - (write a function, its prototype is int continumax (char *outputstr, char *intputstr))
- 热忱与专业齐飞 | 微软最有价值专家项目,广纳微软技术贡献者!
- [論文翻譯] Generalized Radiograph Representation Learning via Cross-Supervision Between Images
- Bryntum Scheduler Pro 5.0.6 \Gantt\Crack
- Execute function semicolon immediately
- Mask RCNN source code explanation
猜你喜欢
随机推荐
On the continuous chain use of promise then
How to install a pagoda on IBM's free machine
Sequence traversal BFS (breadth first)
如何在本机连接优炫数据库
A Mobile Telematics Pattern Recognition Framework for Driving Behavior Extraction
跨域问题(CORS)详细说明和解决
Concis组件库 | 暗黑模式设计
在代码评审中用好这7招,很容易就能建立起你的反对同盟
Cartopy绘图入门指南
ARC110F Esoswap
lvs看这篇就够了
还有人不会这些数据分析小案例吗?一招教你招聘数据可视化~
C language program practice - (write a function, its prototype is int continumax (char *outputstr, char *intputstr))
随机森林学习笔记
Study notes of Gu Yujia on July 20, 2022
Bryntum Scheduler Pro 5.0.6 \Gantt\Crack
禅道管理员忘记密码找回密码
I, AI doctoral student, online crowdfunding research topic
What are the requirements for docking with the third-party payment interface?
Mecol Studio - harmonyos second assignment