【发布时间】:2018-06-21 21:55:35
【问题描述】:
假设我有一个 2 x 3 矩阵,我想创建一个 6 x 2 x 3 矩阵,其中第一维中的每个元素都是原始的 2 x 3 矩阵。
在 PyTorch 中,我可以这样做:
import torch
from torch.autograd import Variable
import numpy as np
x = np.array([[1, 2, 3], [4, 5, 6]])
x = Variable(torch.from_numpy(x))
# y is the desired result
y = x.unsqueeze(0).expand(6, 2, 3)
在 TensorFlow 中执行此操作的等效方法是什么?我知道unsqueeze() 等同于tf.expand_dims(),但我不知道TensorFlow 有任何等同于expand() 的东西。我正在考虑在 1 x 2 x 3 张量列表上使用 tf.concat,但不确定这是否是最好的方法。
【问题讨论】:
标签: python tensorflow pytorch