What does quot;unsqueezequot; do in Pytorch?(“解压是什么意思在 Pytorch 中做什么?)
问题描述
我无法理解 PyTorch 文档 中的示例如何对应解释:
<块引用>返回一个新的张量,其尺寸为 1,插入到指定位置.[...]
<预><代码>>>>x = torch.tensor([1, 2, 3, 4])>>>torch.unsqueeze(x, 0)张量([[ 1, 2, 3, 4]])>>>torch.unsqueeze(x, 1)张量([[ 1],[2],[3],[4]])如果你看前后数组的形状,你会发现它之前是 (4,)
和之后是 (1, 4)
(当第二个参数是 0
)和 (4, 1)
(当第二个参数是 1代码>).因此,根据第二个参数的值,将
1
插入到 0
或 1
轴的数组形状中.
这与 np.squeeze() 相反
(从 MATLAB 中借用的命名法),它删除了大小为 1
(单例)的轴.
I cannot understand how the example in the PyTorch documentation corresponds to the explanation:
Returns a new tensor with a dimension of size one inserted at the specified position. [...]
>>> x = torch.tensor([1, 2, 3, 4]) >>> torch.unsqueeze(x, 0) tensor([[ 1, 2, 3, 4]]) >>> torch.unsqueeze(x, 1) tensor([[ 1], [ 2], [ 3], [ 4]])
If you look at the shape of the array before and after, you see that before it was (4,)
and after it is (1, 4)
(when second parameter is 0
) and (4, 1)
(when second parameter is 1
). So a 1
was inserted in the shape of the array at axis 0
or 1
, depending on the value of the second parameter.
That is opposite of np.squeeze()
(nomenclature borrowed from MATLAB) which removes axes of size 1
(singletons).
这篇关于“解压"是什么意思在 Pytorch 中做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:“解压"是什么意思在 Pytorch 中做什么?


基础教程推荐
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 筛选NumPy数组 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01