python - 在 TensorFlow.js 中切片 3d 张量

标签 python tensorflow tensorflow.js

如何将以下 TensorFlow Python 代码转换为 TensorFlow.js?

New_tensor = A_3D_tensor[:, :seq_len, :]

最佳答案

您可以使用 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]]]"
*/

关于python - 在 TensorFlow.js 中切片 3d 张量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61749280/

相关文章:

python - 何时使用线程以及使用多少线程

tensorflow - 为 Tensorflow.js 保存 TensorFlow 模型

javascript - tensorflow JS : TypeError: Cannot read property 'fetch' of undefined

python - 四阶龙格-库塔

HTML 中的 Python : Iterating over several lists by changing the name of a variable

python - 在 argparse 中使用另一个选项值作为默认值

tensorflow - 在张量板上显示每个图像的多个步骤

android - Tensorflow 的应用程序相机图像模糊

image - 在 Tensorflow 中调整图像保留纵横比

javascript - Tensorflow.js:简单的线性回归效果不佳