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

  

最新文章

  1. Android大神博客
  2. top命令使用详解
  3. POJ1002 487-3279
  4. C++中“强制转换”的四大天王
  5. tarjan总结
  6. win7下jdk安装环境变量配置
  7. Xcode7真机测试
  8. [oracle]查询一个表中数据的插入时间
  9. JDK8 BigDecimal API-创建BigDecimal源码浅析三
  10. CSS中清除浮动的作用以及如何清除浮动
  11. cdnbest区域里快速配置全部节点的缓存
  12. selenium捕捉视频
  13. Python3基础系列——枚举类型大揭秘
  14. SQL语句内做除法得出百分比
  15. python进程之守护进程
  16. java系列之 原生数据类型
  17. this指针的调整
  18. ASP.NET MVC ScriptBundle 不能加载.min.js文件
  19. Linux下的堆off-by-one的利用
  20. Groovy 与 DSL

热门文章

  1. abp(net core)+easyui+efcore实现仓储管理系统——入库管理之七(四十三)
  2. C - 饭卡
  3. mysql 中UNIQUE KEY 到底是约束还是索引?
  4. DevOps技能自查表
  5. 1098 Insertion or Heap Sort (25分)
  6. 打造一款 刷Java 知识的小程序(一)
  7. 将wxpy的登录二维码放到网页上登录
  8. 汇编刷题:在M单元和N单元分别存有一个8位无符号数36H和95H,要求比较并输出 M大于N 或者 M小于N
  9. redis修改密码以及验证登录,启动服务常用命令
  10. Mac配置hosts文件