import torch
import numpy as np
a = torch.tensor([[[1]]])
#只有一个数据的时候,获取其数值
print(a.item()) #tensor转化为nparray
b = a.numpy()
print(b,type(b),type(a)) #获取张量的形状
a = torch.tensor(np.arange(30).reshape(3,2,5))
print(a)
print(a.shape)
print(a.size())
print(a.size(0)) #形状变换
print(a.view([2,3,5])) #转置
b = torch.tensor(np.arange(15).reshape(3,5))
print(b)
print(b.transpose(0,1))
print(b.T) #最大值
print(b.max(dim=-1)) D:\anaconda\python.exe C:/Users/liuxinyu/Desktop/pytorch_test/day1/张量的属性和方法.py
1
[[[1]]] <class 'numpy.ndarray'> <class 'torch.Tensor'>
tensor([[[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9]], [[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19]], [[20, 21, 22, 23, 24],
[25, 26, 27, 28, 29]]], dtype=torch.int32)
torch.Size([3, 2, 5])
torch.Size([3, 2, 5])
3
tensor([[[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14]], [[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24],
[25, 26, 27, 28, 29]]], dtype=torch.int32)
tensor([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14]], dtype=torch.int32)
tensor([[ 0, 5, 10],
[ 1, 6, 11],
[ 2, 7, 12],
[ 3, 8, 13],
[ 4, 9, 14]], dtype=torch.int32)
tensor([[ 0, 5, 10],
[ 1, 6, 11],
[ 2, 7, 12],
[ 3, 8, 13],
[ 4, 9, 14]], dtype=torch.int32)
torch.return_types.max(
values=tensor([ 4, 9, 14], dtype=torch.int32),
indices=tensor([4, 4, 4])) Process finished with exit code 0

  

pytorch中tensor的属性 类型转换 形状变换 转置 最大值的更多相关文章

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

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

  2. 对pytorch中Tensor的剖析

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

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

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

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

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

  5. pytorch中tensor张量的创建

    import torch import numpy as np print(torch.tensor([1,2,3])) print(torch.tensor(np.arange(15).reshap ...

  6. Pytorch 中 tensor的维度拼接

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

  7. tensorflow中张量(tensor)的属性——维数(阶)、形状和数据类型

    tensorflow的命名来源于本身的运行原理,tensor(张量)意味着N维数组,flow(流)意味着基于数据流图的计算,所以tensorflow字面理解为张量从流图的一端流动到另一端的计算过程. ...

  8. [Pytorch]Pytorch的tensor变量类型转换

    原文:https://blog.csdn.net/hustchenze/article/details/79154139 Pytorch的数据类型为各式各样的Tensor,Tensor可以理解为高维矩 ...

  9. PyTorch中MaxPool的ceil_mode属性

    PyTorch中的MaxPool(最大池化)有一个属性:ceil_mode,默认为False(地板模式),为True时是天花板模式.  

随机推荐

  1. POJ 3070 Fibonacci矩阵快速幂 --斐波那契

    题意: 求出斐波那契数列的第n项的后四位数字 思路:f[n]=f[n-1]+f[n-2]递推可得二阶行列式,求第n项则是这个矩阵的n次幂,所以有矩阵快速幂模板,二阶行列式相乘, sum[ i ] [ ...

  2. VSCode 快速生成 .vue 模版

    VSCode 快速生成 .vue 模版 安装vscode 官网:https://code.visualstudio.com/ 安装 Vetur 插件,识别 vue 文件 插件库中搜索Vetur,点击安 ...

  3. Java系列之数组

    原文首发于微信公众号:jzman-blog,欢迎关注交流! 本来打算温习一下注解方面的内容作为今天的推送,但是来不及写了,那就一起来看一下数组,数组是用来存放一组具有相同类型数据的数据结构,通过下标来 ...

  4. win10 系统中vscode 的终端 shell 设置

    今天,打算开始搞一个个人博客小项目. 主力台式电脑在实验室,于是重新配了一下自己的小破笔记本.系统是之前自己捣鼓的 win10 .在打开终端调试 node 时,发现报了这么一个错. 我刚开始以为是自己 ...

  5. 【JAVA进阶架构师指南】之四:垃圾回收GC

    前言   在[JAVA进阶架构师指南]系列二和三中,我们了解了JVM的内存模型以及类加载机制,其中在内存模型中,我们说到,从线程角度来说,JVM分为线程私有的区域(虚拟机栈/本地方法栈/程序计数器)和 ...

  6. MySQL操作表的约束

    完整性:指数据库的准确性和一致性. 约束:是在表中定义的用于维护数据库完整性的一些规则. 主键:给某一个字段来唯一标识所有记录,值是唯一的,非空的 外键:多个表之间参照的完整性. 一.设置非空约束 u ...

  7. 以太坊代币,USDT归集流程图

    1.用户充值 600 代币 (网站小助手会及时监听到用户的充值信息,并回调给用户填写的URL地址) 2.会员转账600代币,属于大额转账,开始触发系统的自动汇集程序 注:这里系统检测到会员的地址并没有 ...

  8. PowerShell入门简介

    文章更新于:2020-03-03 一.PowerShell简介 说实话,我总感觉 PowerShell 是 cmd 的加强版,但是看官方介绍,功能甚是强大,用处有待我们发掘. 二.PowerShell ...

  9. spring05

    通过静态工厂的方法创建bean:和实例工厂方法: <?xml version="1.0" encoding="UTF-8"?> <beans ...

  10. Google GMS介绍

    Google GMS介绍GMS全称为GoogleMobile Service.GMS目前提供有Search.Search by Voice.Gmail.Contact Sync.Calendar Sy ...