There are many ways one can retrieve the value of the element [i,j] of a tensor2d
Consider the following:
Using slice to retrieve directly the tensor2d starting at the coordinate [i, j] that has the size [1, 1]
h.slice([i, j], 1).as1D().print()
Get the row i as a tensor2d with gather and then the element j with slice
h.gather(tf.tensor1d([i], 'int32')).slice([0, j], [1, 1]).as1D().print()
Using stack to retrieve the row i as tensor1d and slice to retrieve the desired element
h.unstack()[i].slice([j], [1]).print()
const h = tf.tensor2d([45, 48, 45, 54, 5, 7, 8, 10, 54], [3, 3]);
// get the element of index [1, 2]
h.print()
h.gather(tf.tensor1d([1], 'int32')).slice([0, 2], [1, 1]).as1D().print()
h.slice([1, 2], 1).as1D().print()
h.unstack()[1].slice([2], [1]).print()
<html>
<head>
<!-- Load TensorFlow.js -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.12.0"> </script>
</head>
<body>
</body>
</html>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…