pytorch中tensor的属性 类型转换 形状变换 转置 最大值
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的属性 类型转换 形状变换 转置 最大值的更多相关文章
- pytorch中tensor数据和numpy数据转换中注意的一个问题
转载自:(pytorch中tensor数据和numpy数据转换中注意的一个问题)[https://blog.csdn.net/nihate/article/details/82791277] 在pyt ...
- 对pytorch中Tensor的剖析
不是python层面Tensor的剖析,是C层面的剖析. 看pytorch下lib库中的TH好一阵子了,TH也是torch7下面的一个重要的库. 可以在torch的github上看到相关文档.看了半天 ...
- [Pytorch]Pytorch中tensor常用语法
原文地址:https://zhuanlan.zhihu.com/p/31494491 上次我总结了在PyTorch中建立随机数Tensor的多种方法的区别. 这次我把常用的Tensor的数学运算总结到 ...
- pytorch中tensor张量数据基础入门
pytorch张量数据类型入门1.对于pytorch的深度学习框架,其基本的数据类型属于张量数据类型,即Tensor数据类型,对于python里面的int,float,int array,flaot ...
- pytorch中tensor张量的创建
import torch import numpy as np print(torch.tensor([1,2,3])) print(torch.tensor(np.arange(15).reshap ...
- Pytorch 中 tensor的维度拼接
torch.stack() 和 torch.cat() 都可以按照指定的维度进行拼接,但是两者也有区别,torch.satck() 是增加新的维度进行堆叠,即其维度拼接后会增加一个维度:而torch. ...
- tensorflow中张量(tensor)的属性——维数(阶)、形状和数据类型
tensorflow的命名来源于本身的运行原理,tensor(张量)意味着N维数组,flow(流)意味着基于数据流图的计算,所以tensorflow字面理解为张量从流图的一端流动到另一端的计算过程. ...
- [Pytorch]Pytorch的tensor变量类型转换
原文:https://blog.csdn.net/hustchenze/article/details/79154139 Pytorch的数据类型为各式各样的Tensor,Tensor可以理解为高维矩 ...
- PyTorch中MaxPool的ceil_mode属性
PyTorch中的MaxPool(最大池化)有一个属性:ceil_mode,默认为False(地板模式),为True时是天花板模式.
随机推荐
- if-else、switch、while、for
文章主要会涉及如下几个问题: if-else 和 switch-case 两者相比谁的效率会高些?在日常开发中该如何抉择? 如何基于赫夫曼树结构减少 if-else 分支判断次数? 如何巧妙的应用 d ...
- 《Flutter 动画系列》组合动画
老孟导读:在前面的文章中介绍了 <Flutter 动画系列>25种动画组件超全总结 http://laomengit.com/flutter/module/animated_1/ < ...
- Let‘s play computer game(最短路 + dfs找出所有确定长度的最短路)
Let's play computer game Description xxxxxxxxx在疫情期间迷上了一款游戏,这个游戏一共有nnn个地点(编号为1--n1--n1--n),他每次从一个地点移动 ...
- HDU-1421-搬寝室(01背包改编版)
搬寝室是很累的,xhd深有体会.时间追述2006年7月9号,那天xhd迫于无奈要从27号楼搬到3号楼,因为10号要封楼了.看着寝室里的n件物品,xhd开始发呆,因为n是一个小于2000的整数,实在是太 ...
- 如何做监控?Google SRE 解密
监控值班室: @隔壁老王头 SQL执行耗时时间过长,达到了报警阈值[5000ms] 隔壁老王头: @监控值班室 少量报警请忽略,批量关注即可. 监控值班室: @隔壁老王头 订单号[88886666]状 ...
- javascript 3d网页 示例 ( three.js 初探 七)
1 完整代码下载 https://pan.baidu.com/s/1JJyVcP2KqXsd5G6eaYpgHQ 提取码 3fzt (压缩包名: 2020-4-5-demo.zip) 2 图片展示 3 ...
- 在.NET Core中检查证书的到期日期
在 NUnit 测试中,我需要检查证书的有效期. 下面的代码片段可用于使用自定义证书验证回调检查任何证书属性. 所有你需要做的就是在回调中读取你感兴趣的属性,这样你就可以在之后检查它们. DateTi ...
- 1066 Root of AVL Tree (25分)(AVL树的实现)
An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child sub ...
- Java static修饰符
Java static修饰符 static修饰符是静态修饰符,大家写Java第一次接触static就是主函数中的pubic static void main的声明了. 那么static有什么用?本文来 ...
- java仿win7计算器布局
代码: package calculator; import javax.swing.*; import java.awt.*; import java.awt.event.*; public cla ...