我在两个一维数组(a,b)上使用了 TensorFlow.js 框架中的 outerProduct 函数,但我发现很难以常规 javascript 格式获取结果张量的值。
即使在使用 .dataSync 和 Array.from() 之后,我仍然无法获得预期的输出格式。两个一维数组之间的结果外积应该给出一个二维数组,但我得到的是一维数组。
const a = tf.tensor1d([1, 2]);
const b = tf.tensor1d([3, 4]);
const tensor = tf.outerProduct(b, a);
const values = tensor.dataSync();
const array1 = Array.from(values);
控制台.log(array1);
预期的结果是 array1 = [ [ 3, 6 ] , [ 4, 8 ] ],但我得到 array1 = [ 3, 6, 4, 8 ]