欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PyTorch中的torch.cat簡(jiǎn)單介紹

 更新時(shí)間:2022年03月17日 11:09:39   作者:DaYinYi  
這篇文章主要介紹了PyTorch中的torch.cat,包torch包含了多維疑是的數(shù)據(jù)結(jié)構(gòu)及基于其上的多種數(shù)學(xué)操作,包含了多維張量的數(shù)據(jù)結(jié)構(gòu)以及基于其上的多種數(shù)學(xué)運(yùn)算,更多相關(guān)資料?需要的小伙伴可以參考一下

1.toych簡(jiǎn)單介紹

torch包含了多維疑是的數(shù)據(jù)結(jié)構(gòu)及基于其上的多種數(shù)學(xué)操作。

torch包含了多維張量的數(shù)據(jù)結(jié)構(gòu)以及基于其上的多種數(shù)學(xué)運(yùn)算。此外,它也提供了多種實(shí)用工具,其中一些可以更有效地對(duì)張量和任意類型進(jìn)行序列化的工具。

它具有CUDA的對(duì)應(yīng)實(shí)現(xiàn),可以在NVIDIA GPU上進(jìn)行張量運(yùn)算(計(jì)算能力>=3.0)

2. 張量Tensors

torch.is_tensor(obj):如果obj是一個(gè)pytorch張量,則返回True

torch.is_storage(obj):如果obj是一個(gè)pytorch storage對(duì)象,則返回True

torch.numel(input):返回input張量中的元素個(gè)數(shù)。

3.torch.cat

a = torch.ones([1,2])
?
b = torch.ones([1,2])
?
z = torch.cat([a,b],1)
?
a
Out[47]: tensor([[1., 1., 1., 1.]])
?
a
Out[48]: tensor([[1., 1.]])

如果第二個(gè)參數(shù)是1,torch.cat就是將a,b 按列放在一起,大小為torch.Size([1,4])。如果第二個(gè)參數(shù)是0,則按行

行放在一起,大小為 torch.Size([2, 2]) 。

字面理解:torch.cat是將兩個(gè)張量(tensor)拼接在一起,cat是concatenate的意思,即拼接,聯(lián)系在一起。

例子理解:

import torch
A = torch.ones(2,3)
A
#tensor([[1., 1., 1.],
# ? ? ? ?[1., 1., 1.]])
B=2*torch.ones(4,3)
B
#tensor([[2., 2., 2.],
# ? ? ? ?[2., 2., 2.],
# ? ? ? ?[2., 2., 2.],
# ? ? ? ?[2., 2., 2.]])
C = torch.cat((A,B),0) #按維數(shù)0(添加到行)拼接
C
#tensor([[1., 1., 1.],
# ? ? ? ?[1., 1., 1.],
# ? ? ? ?[2., 2., 2.],
# ? ? ? ?[2., 2., 2.],
# ? ? ? ?[2., 2., 2.],
# ? ? ? ?[2., 2., 2.]])
D = 2*torch.ones(2,4)
M = torch.cat((A,D),1) ?# 按維數(shù)1(列)拼接
M
#tensor([[1., 1., 1., 2., 2., 2., 2.],
# ? ? ? ?[1., 1., 1., 2., 2., 2., 2.]])
M.size()
#torch.Size([2, 7])

使用torch.cat((A,B),dim)時(shí),除拼接維數(shù)dim數(shù)值可不同外其余維數(shù)數(shù)值需相同,方能對(duì)齊

到此這篇關(guān)于PyTorch中的torch.cat的文章就介紹到這了,更多相關(guān)torch.cat內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論