IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 人工智能 -> numpy.random.seed torch.manual_seed使用 -> 正文阅读

[人工智能]numpy.random.seed torch.manual_seed使用

Args.seed 数字并不代表产生随机数的多少,比如等于2,并不代表产生第三个随机数的时候会和第一个一样,所以args.seed可以只看做一个编号,只有编号没有变,那么执行一次,就会产生和之前一样的随机数。

import torch
import numpy as np

if __name__ == '__main__':
    # Example of target with class indices
    np.random.seed(2)
    torch.manual_seed(3)
    a = np.random.randn(3,3)
    b = np.random.randn(3,3)
    A = torch.randn(3, 3)
    B = torch.randn(3, 3)

    print(f'a and b are {a} {b}')
    print(f'A and B are {A} {B}')

    np.random.seed(2)
    torch.manual_seed(3)
    c = np.random.randn(3, 3)
    d = np.random.randn(3, 3)
    C = torch.randn(3, 3)
    D = torch.randn(3, 3)
    print(f'c and d are {c} {d}')
    print(f'C and D are {C} {D}')

    np.random.seed(2)
    torch.manual_seed(3)
    e = np.random.randn(3, 3)
    f = np.random.randn(3, 3)
    g = np.random.randn(3, 3)
    E = torch.randn(3, 3)
    F = torch.randn(3, 3)
    G = torch.randn(3, 3)

    print(f'e,f and g are {e} {f} {g}')
    print(f'E,F and G are {E} {F} {G}')

结果输出如下:

a and b are [[-0.41675785 -0.05626683 -2.1361961 ]
 [ 1.64027081 -1.79343559 -0.84174737]
 [ 0.50288142 -1.24528809 -1.05795222]] [[-0.90900761  0.55145404  2.29220801]
 [ 0.04153939 -1.11792545  0.53905832]
 [-0.5961597  -0.0191305   1.17500122]]
A and B are tensor([[ 0.8033,  0.1748,  0.0890],
        [-0.6137,  0.0462, -1.3683],
        [ 0.3375,  1.0111, -1.4352]]) tensor([[ 0.9774,  0.5220,  1.2379],
        [-0.8646,  0.2990,  0.4192],
        [-0.0799,  0.9264,  0.8157]])
c and d are [[-0.41675785 -0.05626683 -2.1361961 ]
 [ 1.64027081 -1.79343559 -0.84174737]
 [ 0.50288142 -1.24528809 -1.05795222]] [[-0.90900761  0.55145404  2.29220801]
 [ 0.04153939 -1.11792545  0.53905832]
 [-0.5961597  -0.0191305   1.17500122]]
C and D are tensor([[ 0.8033,  0.1748,  0.0890],
        [-0.6137,  0.0462, -1.3683],
        [ 0.3375,  1.0111, -1.4352]]) tensor([[ 0.9774,  0.5220,  1.2379],
        [-0.8646,  0.2990,  0.4192],
        [-0.0799,  0.9264,  0.8157]])
e,f and g are [[-0.41675785 -0.05626683 -2.1361961 ]
 [ 1.64027081 -1.79343559 -0.84174737]
 [ 0.50288142 -1.24528809 -1.05795222]] [[-0.90900761  0.55145404  2.29220801]
 [ 0.04153939 -1.11792545  0.53905832]
 [-0.5961597  -0.0191305   1.17500122]] [[-0.74787095  0.00902525 -0.87810789]
 [-0.15643417  0.25657045 -0.98877905]
 [-0.33882197 -0.23618403 -0.63765501]]
E,F and G are tensor([[ 0.8033,  0.1748,  0.0890],
        [-0.6137,  0.0462, -1.3683],
        [ 0.3375,  1.0111, -1.4352]]) tensor([[ 0.9774,  0.5220,  1.2379],
        [-0.8646,  0.2990,  0.4192],
        [-0.0799,  0.9264,  0.8157]]) tensor([[ 0.4952, -0.1643, -0.6780],
        [-1.0591,  0.7477,  0.2389],
        [-0.3922,  0.1519, -1.1837]])

  人工智能 最新文章
2022吴恩达机器学习课程——第二课(神经网
第十五章 规则学习
FixMatch: Simplifying Semi-Supervised Le
数据挖掘Java——Kmeans算法的实现
大脑皮层的分割方法
【翻译】GPT-3是如何工作的
论文笔记:TEACHTEXT: CrossModal Generaliz
python从零学(六)
详解Python 3.x 导入(import)
【答读者问27】backtrader不支持最新版本的
上一篇文章      下一篇文章      查看所有文章
加:2022-01-01 13:53:53  更:2022-01-01 13:54:24 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/19 4:48:15-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码