在TensorFlow.js中切割一个三维张量器

问题描述 投票:1回答:1

如何将以下TensorFlow的Python代码翻译成TensorFlow.js?

New_tensor = A_3D_tensor[:, :seq_len, :]
python tensorflow tensorflow.js
1个回答
1
投票

你可以用 slice 方法(或者,对于更复杂的情况,用 stridedSlice):

const t = tf.range(0, 36, 1).as3D(2, 6, 3);
const seq_len = 4;
const t_sliced = t.slice([0, 0, 0], [-1, seq_len, -1]);
t_sliced.print();
/*
"Tensor
    [[[0 , 1 , 2 ],
      [3 , 4 , 5 ],
      [6 , 7 , 8 ],
      [9 , 10, 11]],

     [[18, 19, 20],
      [21, 22, 23],
      [24, 25, 26],
      [27, 28, 29]]]"
*/
© www.soinside.com 2019 - 2024. All rights reserved.