當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Tensorflow.js tf.argMin()用法及代碼示例

Tensorflow.js是Google開發的開源庫,用於在瀏覽器或節點環境中運行機器學習模型和深度學習神經網絡。

tf.argMin()函數用於沿軸返回指定張量的最小值的索引。輸出結果具有與輸入相同的形狀,但沿軸的尺寸已刪除。

用法:

tf.argMin (x, axis)

參數:此函數接受兩個參數,如下所示:

  • x:輸入張量。
  • axis:指定要減小的尺寸。它是一個可選參數,默認值為0。

返回值:它沿軸返回最小值索引的張量。



範例1:

Javascript


// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Initializing a some tensors 
const a = tf.tensor1d([0, 1]);
const b = tf.tensor1d([5, 3]);
const c = tf.tensor1d([6, 3, 5, 2]);
  
// Calling the .argMin() function over 
// the above tensors
a.argMin().print();
b.argMin().print();
c.argMin().print();

輸出:

Tensor
   0
Tensor
   1
Tensor
   3

範例2:

Javascript


// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Initializing a some tensors 
const a = tf.tensor1d([0, 1]);
const b = tf.tensor2d([9, 5, 2, 8], [2, 2]);
const c = tf.tensor1d([6, 4, 7]);
  
// Initializing a axis parameters
const axis1 = -1;
const axis2 = -2;
const axis3 = 0;
  
// Calling the .argMin() function over 
// the above tensors
a.argMin(axis1).print();
b.argMin(axis2).print();
c.argMin(axis3).print();

輸出:

Tensor
   0
Tensor
   [1, 0]
Tensor
   1

參考: https://js.tensorflow.org/api/latest/#argMin

相關用法


注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 Tensorflow.js tf.argMin() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。