Pytorch_1_基本语法

一、Pytorch的基本元素操作

1.引入torch

复制代码
from __future__ import print_function
import torch

2.创建矩阵

复制代码
x = torch.empty(5,3)
print(x)

3.输出结果:

tensor(\[7.9191e+34, 1.1259e+24, 1.2359e-42,

4.0824e-40, 1.1379e-35, 2.5353e+30,

8.4078e-45, 2.6709e-42, 7.7558e-40,

2.9130e-33, 2.5353e+30, 9.6690e-44,

7.5524e+28, 5.2839e-11, 1.3458e-14])

4.指定一个全零矩阵并可指定数据元素的类型为long

复制代码
x = torch.zeros(5,3, dtype=torch.long)
print(x)

5.输出结果

tensor(\[0, 0, 0,

0, 0, 0,

0, 0, 0,

0, 0, 0,

0, 0, 0])

未完待续。。。

相关推荐
ghie9090几秒前
基于图像处理的铁路裂缝检测系统
图像处理·人工智能
EntyIU1 分钟前
Tools使用指南
python·langchain
EnCi Zheng1 分钟前
09abb-SwiGLU激活函数
人工智能
MageGojo2 分钟前
实时电影票房 API 接入实战:用 GET 请求获取影片票房榜单数据
python·电影票房·api 接口接入
菜鸡旭旭2 分钟前
【AI培训中台项目介绍】
人工智能
Elastic 中国社区官方博客3 分钟前
Hacknight Beijing:基于阿里云与 Elastic 构建 AI Agents
大数据·运维·人工智能·elasticsearch·搜索引擎·阿里云·云计算
柏舟飞流5 分钟前
大数据与 AI 融合:高阶架构与实践
大数据·人工智能·架构
weixin_468466857 分钟前
Scrapling 高效网络爬虫实战指南
爬虫·python·编程·scrapling
yubo05098 分钟前
计算机视觉第十课:摄像头实时 颜色 + 形状 识别
python·opencv·计算机视觉
Database_Cool_9 分钟前
数据仓库弹性扩缩容怎么实现?阿里云 AnalyticDB MySQL Serverless 弹性架构详解
数据库·人工智能·阿里云