首页 > 解决方案 > TensorFlow.js 收集字符串张量

问题描述

我是 TensorFlow.js 的新手并且有一个问题.. 通过索引从列表中收集元素时

const x = tf.tensor1d([32, 43, 25, 65])
const indices = tf.tensor1d([1, 3, 3], 'int32');
x.gather(indices).print();

// Tensor
//    [43, 65, 65]

但是当 x 是字符串张量时,它不起作用。

const x = tf.tensor1d(["a1", "a2", "a3", "a4"]);
const indices = tf.tensor1d([1, 3, 3], 'int32');
x.gather(indices).print();

// Uncaught Error: Argument 'x' passed to 'gather' must be numeric tensor, but got string tensor

我错过了什么吗?

标签: tensorflowtensorflow.js

解决方案


推荐阅读