与张量流的火炬的非挤压等效力是什么?

问题描述 投票:0回答:2

与tensorflow相比,火炬的非挤压等效性是什么?

#tensorflow auto-broadcasts singleton dimensions
lower_bounds = tf.argmax(set_1[:, :2].unsqueeze(1), set_2[:, :2].unsqueeze(0))  # (n1, n2, 2)
upper_bounds = tf.argmin(set_1[:, 2:].unsqueeze(1), set_2[:, 2:].unsqueeze(0))  # (n1, n2, 2)
tensorflow pytorch tensorflow2.0 torch
2个回答
2
投票

也许您想尝试一下:tf.expand_dims(x, axis)


1
投票

tf.expand_dims是您要寻找的。

tf.expand_dims(
    input, axis, name=None
)

给定张量输入,此操作在输入形状的尺寸索引轴上插入尺寸为1的尺寸。尺寸索引轴从零开始;如果为轴指定负数,则从末尾算起。

示例

t = [[1, 2, 3],[4, 5, 6]]       # [2, 3]
tf.shape(tf.expand_dims(t, 0))  # [1, 2, 3]
tf.shape(tf.expand_dims(t, 1))  # [2, 1, 3]
tf.shape(tf.expand_dims(t, -1)) # [2, 3, 1]
© www.soinside.com 2019 - 2024. All rights reserved.