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:\anaconda\python.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

  

pytorch中tensor张量的创建的更多相关文章

  1. pytorch中tensor张量数据基础入门

    pytorch张量数据类型入门1.对于pytorch的深度学习框架,其基本的数据类型属于张量数据类型,即Tensor数据类型,对于python里面的int,float,int array,flaot ...

  2. pytorch中tensor数据和numpy数据转换中注意的一个问题

    转载自:(pytorch中tensor数据和numpy数据转换中注意的一个问题)[https://blog.csdn.net/nihate/article/details/82791277] 在pyt ...

  3. 对pytorch中Tensor的剖析

    不是python层面Tensor的剖析,是C层面的剖析. 看pytorch下lib库中的TH好一阵子了,TH也是torch7下面的一个重要的库. 可以在torch的github上看到相关文档.看了半天 ...

  4. [Pytorch]Pytorch中tensor常用语法

    原文地址:https://zhuanlan.zhihu.com/p/31494491 上次我总结了在PyTorch中建立随机数Tensor的多种方法的区别. 这次我把常用的Tensor的数学运算总结到 ...

  5. pytorch中tensor的属性 类型转换 形状变换 转置 最大值

    import torch import numpy as np a = torch.tensor([[[1]]]) #只有一个数据的时候,获取其数值 print(a.item()) #tensor转化 ...

  6. Pytorch 中 tensor的维度拼接

    torch.stack() 和 torch.cat() 都可以按照指定的维度进行拼接,但是两者也有区别,torch.satck() 是增加新的维度进行堆叠,即其维度拼接后会增加一个维度:而torch. ...

  7. pytorch 中的数据类型,tensor的创建

    pytorch中的数据类型 import torch a=torch.randn(2,3) b=a.type() print(b) #检验是否是该数据类型 print(isinstance(a,tor ...

  8. [PyTorch 学习笔记] 1.2 Tensor(张量)介绍

    本章代码: https://github.com/zhangxiann/PyTorch_Practice/blob/master/lesson1/tensor_introduce1.py https: ...

  9. Pytorch中的variable, tensor与numpy相互转化的方法

    1.将numpy矩阵转换为Tensor张量 sub_ts = torch.from_numpy(sub_img) #sub_img为numpy类型 2.将Tensor张量转化为numpy矩阵 sub_ ...

随机推荐

  1. js事件的获取

    获取元素样式属性 Method DES clientWidth 获取元素宽度 clientHeight 获取元素高度(内容+内边距) document.body.clientWidth 获取body宽 ...

  2. CSS躬行记(2)——伪类和伪元素

    一.伪类选择器 伪选择器弥补了常规选择器的不足,能够实现一些特殊情况下的样式,例如在鼠标悬停时或只给字符串中的第一个字符指定样式.与类选择器类似,可以从HTML元素的class属性中查看到,但伪选择器 ...

  3. python 控制台输出美化

    #格式: 设置颜色开始 :\033[显示方式;前景色;背景色m #说明: 前景色 背景色 颜色 --------------------------------------- 黑色 红色 绿色 黃色 ...

  4. linux 访问windows 共享文件

    用到的方法是 CIFS (Common Internet File System)windows自己的网络文件系统 操作系统: Linux为 debian. Windows 为 windows 8   ...

  5. A AK的距离

    时间限制 : - MS   空间限制 : - KB  评测说明 : 1s,128m 问题描述 同学们总想AK.于是何老板给出一个由大写字母构成的字符串,他想你帮忙找出其中距离最远的一对'A'和'K'. ...

  6. 使用IDEA编写JDBC

    省去下载MySQL的过程,创建数据库demo 首先在下载的Java服务中将此jar包复制到项目中的一个空文件夹中 在当前工程下新建目录lib(名字可自定) 找到MySQL的Java服务的jar包 打开 ...

  7. 1068 Find More Coins (30分)(dp)

    Eva loves to collect coins from all over the universe, including some other planets like Mars. One d ...

  8. JS数据结构与算法——栈

    JS数据结构与算法--栈 1.栈结构概念 栈(Stack)是一种先进后出(LIFO Last in First out)的线性表,先进栈的将会比后进栈的先出栈. 栈的限制是仅允许在一端进行插入和删除运 ...

  9. 从一个慢查询到MySQL字符集编码

    从一个慢查询到MySQL字符集编码 目录 从一个慢查询到MySQL字符集编码 1. 问题起源 2. MySQL字符集和字符集排序规则 2.1 字符集相关概念 2.2 MySQL中的字符集和字符集排序规 ...

  10. 【php】正则表达式

    一.生活当中的正则表达式: a)Notepad++.word等这些具有编辑功能的软件,都具有一个查找.替换的功能,这个功能,其实就属于正则模式的一种匹配.替换:包括windows当中可以实现的查找,也 ...