Tensorflow.js是Google開發的開源庫,用於在瀏覽器或節點環境中運行機器學習模型和深度學習神經網絡。
tf.TensorBuffer 類 .get() 方法用於返回給定位置的指定緩衝區中的值。
用法:
get (...locations)
參數:此方法接受單個參數,如下所示:
- locations:指定的位置索引。
返回值:它返回指定位置索引處的值。
範例1:
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Creating a buffer of 2*2 dimensions
const buffer = tf.buffer([2, 2]);
// Setting values at particular indices.
buffer.set(5, 0, 0);
buffer.set(10, 1, 0);
// Getting the values for the
// specified indices with the
// help of .get() function
console.log(buffer.get(0, 0));
console.log(buffer.get(1, 0));
輸出:
5 10
範例2:
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Creating a buffer of 3*3 dimensions
const buffer = tf.buffer([3, 3]);
// Setting values at particular indices.
buffer.set(5, 0, 0);
buffer.set(10, 0, 1);
buffer.set(15, 1, 0);
buffer.set(20, 1, 1);
buffer.set(25, 2, 0);
buffer.set(30, 2, 1);
buffer.set(35, 2, 2);
// Getting the values for the
// specified indices with
// the help of .get() functions
console.log(buffer.get(0, 0));
console.log(buffer.get(0, 1));
console.log(buffer.get(1, 0));
console.log(buffer.get(2, 0));
console.log(buffer.get(2, 1));
console.log(buffer.get(2, 2));
輸出:
5 10 15 25 30 35
參考: https://js.tensorflow.org/api/latest/#tf.TensorBuffer.get
相關用法
- Javascript weakMap.get()用法及代碼示例
- JQuery get()用法及代碼示例
- JQuery Misc get()用法及代碼示例
- Javascript Reflect.get()用法及代碼示例
- Javascript handler.get()用法及代碼示例
- HTML DOM customElements get()用法及代碼示例
- p5.js Table get()用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 Tensorflow.js tf.TensorBuffer class .get() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。