在Tensorflow.js中获取张量中项目的值

Pra*_*yal 5 indexing tensor tensorflow.js

指定索引后,如何从Tensorflow.js中的张量中获取值?

Ble*_*Key 6

您可以为此使用datasync。

const newTensor = tf.tensor2d([[2,4],[5,6]]);
const tensorData = newTensor.dataSync();
console.log("data[0] is " + tensorData[0]);
console.log("data[3] is " + tensorData[3]);
Run Code Online (Sandbox Code Playgroud)

https://codepen.io/anon/pen/NMKgeO?editors=1011


Pra*_*yal 2

const newTensor = tf.tensor2d([[2,4], [5,6]])
newTensor.get([0]) ##returns 2
newTensor.get([3]) ##returns 6
Run Code Online (Sandbox Code Playgroud)

值得庆幸的是,所有这些都返回一个数字而不是张量。

  • 最新版本中不再存在此“get”功能。 (3认同)