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])

未完待续。。。

相关推荐
钱栈up29 分钟前
GitHub 热榜上手|anthropics/skills:18.9万星的 Claude 技能库
python·开源·github
钱栈up1 小时前
烧结秤校准改造:一个 0.93 系数差点让整条日报线算错数
爬虫·python·数据分析
IT空门:门主7 小时前
Spring AI 2.1.0 更新了什么:从 2.0 升上来的完整梳理
人工智能·python·spring
AI创界者8 小时前
Python 进阶实战(七十章):遗留系统重构、渐进式绞杀与技术债治理实战
人工智能·python·aigc
ZhengEnCi9 小时前
电脑操作 Agent 一直点不中:截图没更新时,提示词该怎么改才能停止瞎试
人工智能·python·agent
甲维斯9 小时前
使用 GPT6.2+UE5 做3D游戏的第一天!
人工智能
字节跳动视频云技术团队9 小时前
不用自建后端,前端页面也能接入云端数据了:Pages Data SDK 正式上线
人工智能·敏捷开发
苏三的开发日记9 小时前
5 个 UI Skill 选型对照表:从需求梳理到方案汇报
人工智能
Wellijohn10 小时前
dict、tuple、dataclass 还是 slots?我把 6 种数据载体的 8 项开销全测了一遍
后端·python·性能优化