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. Python第七章-面向对象

    面向对象编程基础 一.面向对象概念 1.1 什么是面向过程 ​ 就是分析出解决问题所需要的步骤,然后用函数把这些步骤一步一步实现,使用的时候一个一个依次调用就可以了. ​ 生活中的的例子举例. 1.2 ...

  2. Springboot + Freemarker(一)

    Maven pom文件配置 <parent> <groupId>org.springframework.boot</groupId> <artifactId& ...

  3. gold 波浪

  4. [POJ1835]宇航员<模拟>

    链接:http://poj.org/problem?id=1835 题干太长我就不放描述了. 一道大模拟 看着就脑壳疼. 难点可能在于方向的确认上 要明确当前的头朝向和脸朝向,才能进行处理 一个小小坑 ...

  5. Salesforce LWC学习(十五) Async 以及 Picklist 公用方法的实现

    本篇参考:salesforce 零基础学习(六十二)获取sObject中类型为Picklist的field values(含record type) https://developer.salesfo ...

  6. 2019级第一次月赛暨ACM工作室第一次招新赛、补题赛

    A:最简单签到,没有之一 Description 此题简单如题意,就是求最大值 Input 多组输入 每组输入输入一串字符串(包括字母和数字),长度小于500 Output 每行输出字符ASCII值与 ...

  7. Vertica的这些事(五)——-谈谈vertica的flex-table

    Json格式对于现在所有的软件开发者都不陌生,很多数据格式都用他来存储,我们来看一下vertica是怎么处理json数据的.这就是vertica的flex table! 首先创建一个json文件: { ...

  8. python:<class 'numpy.ndarray'>的学习

    在学习opencv-python的时候,给出图片地址再调用cv2.imread("地址"),发现出创建的是numpy类型的ndarray对象,用来存放多维数组的对象 # 导入cv2 ...

  9. Springboot系列(四)web静态资源配置详解

    Springboot系列(四)web静态资源配置 往期精彩 SpringBoot系列(一)idea新建Springboot项目 SpringBoot系列(二)入门知识 SpringBoot系列(三)配 ...

  10. docker 容器容器之间网络通信 docker-compose.yaml 配置固定ip

    1.创建自己的桥接网络 $ docker network create --subnet=172.18.0.0/16 mynetwork 2.docker-compose.yaml 文件格式demo ...