当前位置:网站首页>【PyTorch 07】 动手学深度学习——chapter_preliminaries/ndarray 习题动手版
【PyTorch 07】 动手学深度学习——chapter_preliminaries/ndarray 习题动手版
2022-07-07 08:30:00 【ECCUSXR】
目录
2. 使用 arange 创建一个行向量 x, 这个行向量包含以0开始的前12个整数。
3. 通过张量的 shape 属性来访问张量 x(沿每个轴的长度)的形状
4. 只想知道张量中元素的总数,可以检查它的大小(size)
5. 把张量 x 从形状为(12,)的行向量转换为形状为(3,4)的矩阵。
6. 创建一个形状为(2,3,4)的张量,其中所有元素都设置为0。
7. 创建一个形状为(2,3,4)的张量,其中所有元素都设置为1。
8. 创建一个形状为(3,4)的张量。 其中的每个元素都从均值为0、标准差为1的标准高斯分布(正态分布)中随机采样。
9. torch.tensor 创建一个 (3,4)的二维数组。
15.使用 arange 创建一个 3*1 的数组 a 和 1*2 的数组b
17. 取出二维数组 X 中选择 最后一行元素、第二行到第三行元素
20、 将X转成numpy赋给A,再将A转成tensor的形式给B
1. 导入torch
2. 使用 arange
创建一个行向量 x
, 这个行向量包含以0开始的前12个整数。
3. 通过张量的 shape
属性来访问张量 x
(沿每个轴的长度)的形状
4. 只想知道张量中元素的总数,可以检查它的大小(size)
5. 把张量 x
从形状为(12,)的行向量转换为形状为(3,4)的矩阵。
6. 创建一个形状为(2,3,4)的张量,其中所有元素都设置为0。
7. 创建一个形状为(2,3,4)
的张量,其中所有元素都设置为1。
8. 创建一个形状为(3,4)的张量。 其中的每个元素都从均值为0、标准差为1的标准高斯分布(正态分布)中随机采样。
9. torch.tensor 创建一个 (3,4)的二维数组。
【运算符】
10. 实现以下两个数组的加减乘除
x = torch.tensor([1.0, 2, 4, 8])
y = torch.tensor([2, 2, 2, 2])
11. 给下面的数组求幂运算
x = torch.tensor([1.0, 2, 4, 8])
12. 以下两个数组,按行/按列拼接
X = torch.arange(12, dtype=torch.float32).reshape((3,4))
Y = torch.tensor([[2.0, 1, 4, 3], [1, 2, 3, 4], [4, 3, 2, 1]])
13. 判断下面两个同型数组每个元素是否相等
X = torch.arange(12, dtype=torch.float32).reshape((3,4))
Y = torch.tensor([[2.0, 1, 4, 3], [1, 2, 3, 4], [4, 3, 2, 1]])
14. 计算X数组中所有元素的和
X = torch.arange(12, dtype=torch.float32).reshape((3,4))
【广播机制】
15. 使用 arange
创建一个 3*1 的数组 a 和 1*2 的数组b
16. 尝试将上面两个数组直接相加,查看情况。
【索引和切片】
17. 取出二维数组 X 中选择 最后一行元素、第二行到第三行元素
X = torch.arange(12, dtype=torch.float32).reshape((3,4))
18、修改二维数组 X第1行第2列的值为9并写入矩阵
X = torch.arange(12, dtype=torch.float32).reshape((3,4))
19、修改二维数组 X 第0行和第1行所有元素为12.
X = torch.arange(12, dtype=torch.float32).reshape((3,4))
【转换对象】
20、将X转成numpy赋给A,再将A转成tensor的形式给B
X = torch.arange(12, dtype=torch.float32).reshape((3,4))
21、输出a的原数、字符型、浮点型
a = torch.tensor([3.5])
边栏推荐
- How embedded engineers improve work efficiency
- 成为优秀的TS体操高手 之 TS 类型体操前置知识储备
- The mobile terminal automatically adjusts the page content and font size by setting rem
- [detailed explanation of Huawei machine test] tall and short people queue up
- 555电路详解
- CAS mechanism
- Using U2 net deep network to realize -- certificate photo generation program
- HDU-2196 树形DP学习笔记
- 软考中级有用吗??
- Leetcode-303: region and retrieval - array immutable
猜你喜欢
ThreadLocal is not enough
打算参加安全方面工作,信息安全工程师怎么样,软考考试需要怎么准备?
Talking about the return format in the log, encapsulation format handling, exception handling
1324:【例6.6】整数区间
Vs code specifies the extension installation location
【实战】霸榜各大医学分割挑战赛的Transformer架构--nnFormer
P1223 排队接水/1319:【例6.1】排队接水
Application of OpenGL gllightfv function and related knowledge of light source
Several schemes of building hardware communication technology of Internet of things
leetcode-560:和为 K 的子数组
随机推荐
P1031 [noip2002 improvement group] average Solitaire
软考中级电子商务师含金量高嘛?
Factorial implementation of large integer classes
[homework] 2022.7.6 write your own cal function
使用U2-Net深层网络实现——证件照生成程序
Serial communication relay Modbus communication host computer debugging software tool project development case
Multisim--软件相关使用技巧
枪出惊龙,众“锁”周之
Smart city construction based on GIS 3D visualization technology
【实战】霸榜各大医学分割挑战赛的Transformer架构--nnFormer
搭建物联网硬件通信技术几种方案
555 circuit details
字符串格式化
Trajectory planning for multi robot systems: methods and Applications Overview reading notes
gym安装踩坑记录
Sword finger offer 38 Arrangement of strings [no description written]
[牛客网刷题 Day6] JZ27 二叉树的镜像
Hdu-2196 tree DP learning notes
2022.7.6DAY598
深入分析ERC-4907协议的主要内容,思考此协议对NFT市场流动性意义!