Pytorch数据类型转换
2024-10-18 22:06:43
Pytorch数据类型转换
载入模块生成数据
import torch
import numpy as np
a_numpy = np.array([1,2,3])
Numpy转换为Tensor
a_tensor = torch.from_numpy(a_numpy)
print(a_tensor)
Tensor转换为Numpy
a_numpy = a_tensor.numpy()
print(a_numpy)
Int, float 转换为tensor
c = torch.tensor(2)
print(c)
tensor 转换为int
c = c.item()
print(c)
Numpy转换为Variable
a_variable = Variable(torch.from_numpy(a_numpy))
print(a_variable)
Variable转换为Numpy
a_numpy = a_variable.data.numpy()
print(a_numpy)
最新文章
- 将字母变为其下个字母(abc变为bcd)
- 笔记本_Lenovo_G480
- oracle初次使用连接不上
- 【打表】HDOJ-2089-不要62
- 通过javascript实现页面的横竖屏固定
- C#对数字添加逗号,千分位
- PAT (Advanced Level) 1073. Scientific Notation (20)
- 24、手把手教你Extjs5(二十四)模块Form的自定义的设计[3]
- Zabbix Agent for Windows部署(五)
- halcon开发必读
- 异步任务神器 Celery-入门
- Java 实现异步调用
- Linux 安装 ffmpeg
- aruba 802.11ac协议
- windows下搭建permeate漏洞测试系统实战
- Java开发新手经常遇到的一些问题
- 3PC
- 通过管道传输快速将MySQL的数据导入Redis
- Hadoop(hadoop,HBase)组件import到eclipse
- 1.1(Spring学习笔记)Spring-事务基础
热门文章
- Java13 闪亮来袭,你是否还停留在 Java8
- 当接口请求体里的日期格式跟web页面日期格式不一致时,该如何处理呢?
- Node 之 Express 4x 骨架详解
- WEB引入Google思源黑体
- java基础(17):包装类、System、Math、Arrays、大数据运算
- java基础(7):自定义类、ArrayList集合
- DevExpress的下拉框控件ComboBoxEdit控件的使用
- 敏捷软件开发_设计原则<;三>;
- js 时分秒转化为秒
- EGit(Git Eclipse Plugin)使用