zoukankan      html  css  js  c++  java
  • pytorch中tensor张量的创建

    import torch
    import numpy as np
    
    print(torch.tensor([1,2,3]))
    print(torch.tensor(np.arange(15).reshape(3,5)))
    print(torch.empty([3,4]))
    print(torch.ones([3,4]))
    print(torch.zeros([3,4]))
    #0-1之间的随机数
    print(torch.rand([2,3]))
    #3-10之间的随机整数
    print(torch.randint(3,10,(2,2)))
    #正态分布,均值为0,方差为1
    print(torch.randn([3,4]))
    
    
    
    
    D:anacondapython.exe C:/Users/liuxinyu/Desktop/pytorch_test/day1/tensor.py
    tensor([1, 2, 3])
    tensor([[ 0,  1,  2,  3,  4],
            [ 5,  6,  7,  8,  9],
            [10, 11, 12, 13, 14]], dtype=torch.int32)
    tensor([[0., 0., 0., 0.],
            [0., 0., 0., 0.],
            [0., 0., 0., 0.]])
    tensor([[1., 1., 1., 1.],
            [1., 1., 1., 1.],
            [1., 1., 1., 1.]])
    tensor([[0., 0., 0., 0.],
            [0., 0., 0., 0.],
            [0., 0., 0., 0.]])
    tensor([[0.5792, 0.9149, 0.3303],
            [0.6756, 0.5236, 0.0648]])
    tensor([[9, 3],
            [4, 7]])
    tensor([[ 1.2060, -0.8728, -0.6619,  1.2589],
            [-0.8896, -0.1648, -0.0978, -0.8487],
            [ 0.2621,  0.9406,  0.0079,  0.0284]])
    
    Process finished with exit code 0
    

      

    多思考也是一种努力,做出正确的分析和选择,因为我们的时间和精力都有限,所以把时间花在更有价值的地方。
  • 相关阅读:
    java学习笔记(四)
    Sigmoid 函数
    Neural Architectures for Named Entity Recognition 学习笔记
    java学习笔记(三)
    java学习笔记(二)
    Java学习笔记(一)
    shell 小技巧
    Network Embedding 相关论文
    C++学习笔记(二)
    js判断某字符出现的个数
  • 原文地址:https://www.cnblogs.com/LiuXinyu12378/p/12292972.html
Copyright © 2011-2022 走看看