如何使两个 tensor 纬度相等?
Created by: FantasticSix
你好,我想让两个tensor 的dim 一致,该如何操作呢? 具体来说,我想让emb_2 的dims 和emb_1 的dims 一致,是[-1, 64] 而不是[-1, -1],请问改如何实现呢
代码如下+++++++++++++++++++ import numpy as np import paddle.fluid as fluid data = fluid.layers.data(name='sequence', shape=[1], dtype='int64', lod_level=1)
emb_1 = fluid.layers.embedding(input=data, size=[128, 64]) print(emb_1)
emb_1_shape = fluid.layers.shape(emb_1) emb_1_shape.stop_gradient = True ###因为需要做一些操作需要把 embedding 给reshape tmp = fluid.layers.reshape(x=emb_1, shape=[-1]) emb_2 = fluid.layers.reshape(x=tmp, shape=[emb_1_shape[0], emb_1_shape[1]]) print(emb_2)