当前位置:网站首页>【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])边栏推荐
- Jump to the mobile terminal page or PC terminal page according to the device information
- 那些易混淆的概念(三):function和class
- The variables or functions declared in the header file cannot be recognized after importing other people's projects and adding the header file
- Summary of router development knowledge
- mysql插入数据创建触发器填充uuid字段值
- Sword finger offer 38 Arrangement of strings [no description written]
- High number_ Chapter 1 space analytic geometry and vector algebra_ Quantity product of vectors
- 想考中级软考,一般需要多少复习时间?
- Easyexcel read write simple to use
- Study summary of postgraduate entrance examination in September
猜你喜欢

成为优秀的TS体操高手 之 TS 类型体操前置知识储备

Encrypt and decrypt stored procedures (SQL 2008/sql 2012)

leetcode-560:和为 K 的子数组

The variables or functions declared in the header file cannot be recognized after importing other people's projects and adding the header file

leetcode-304:二维区域和检索 - 矩阵不可变

JMeter installation

浅谈日志中的返回格式封装格式处理,异常处理

CAS机制

IO模型复习

555 circuit details
随机推荐
BigDecimal value comparison
ThreadLocal会用可不够
Slurm资源管理与作业调度系统安装配置
打算参加安全方面工作,信息安全工程师怎么样,软考考试需要怎么准备?
JMeter loop controller and CSV data file settings are used together
Common shortcut keys in IDA
中级网络工程师是什么?主要是考什么,有什么用?
小程序跳转H5,配置业务域名经验教程
IIC基本知识
Remote meter reading, switching on and off operation command
About hzero resource error (groovy.lang.missingpropertyexception: no such property: weight for class)
Study summary of postgraduate entrance examination in September
CSAPP Bomb Lab 解析
Review of the losers in the postgraduate entrance examination
电表远程抄表拉合闸操作命令指令
Openinstall and Hupu have reached a cooperation to mine the data value of sports culture industry
施努卡:机器视觉定位技术 机器视觉定位原理
BUUCTF---Reverse---reverse1
Socket通信原理和实践
P1031 [noip2002 improvement group] average Solitaire