[python]torch.cat和numpy.concatenate对应拼接

torch版本:

import torch

x1 = torch.tensor([[11, 21, 31], [21, 31, 41]], dtype=torch.int)
x1.shape  # torch.Size([2, 3])
x2
x2 = torch.tensor([[12, 22, 32], [22, 32, 42]], dtype=torch.int)
x2.shape  # torch.Size([2, 3])
inputs = [x1, x2]
#print(inputs)
output = torch.cat(inputs, dim=0)
print(output)

对应numpy版本:

import numpy as np
x1 = np.array([[11, 21, 31], [21, 31, 41]], dtype=np.int32)
x1.shape  # torch.Size([2, 3])
x2
x2 = np.array([[12, 22, 32], [22, 32, 42]], dtype=np.int32)
x2.shape  # torch.Size([2, 3])
inputs = [x1, x2]
print(inputs)
output = np.concatenate(inputs, axis=0)
print(output)

因此torch.cat函数和Numpy中concatenate对应,numpy里面是没有cat函数的

Original: https://blog.csdn.net/FL1623863129/article/details/128221181
Author: FL1623863129
Title: [python]torch.cat和numpy.concatenate对应拼接

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/763266/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球