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


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

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

.meshgrid() 函數用於廣播參數,以便在 N-D 網格上進行分析。此外,對於一維坐標數組,即 *args,此方法返回 N-D 坐標數組的輸出列表,用於分析 N-D 網格上給定 N 的表達式。

注意:此函數支持笛卡爾 ‘xy’ 以及矩陣 ‘ij’ 索引協議。如果索引參數固定為默認值,即 ‘xy’,則交換前兩個測量的廣播命令。

用法:

tf.meshgrid(x?, y?, __2?)



Parameters: 

  • x:規定的張量以及排名 geq 一。它是可選的,可以是 tf.Tensor、TypedArray 或 Array 類型。
  • y:規定的張量以及排名 geq 一。它是可選的,可以是 tf.Tensor、TypedArray 或 Array 類型。
  • __2:它是可選參數,類型為 { indexing?:string; }.

返回值:它返回tf.Tensor []。

範例1:使用等級 1 的張量。

Javascript


// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Defining first tensor
const t1 = [1, 1, 3];
  
// Defining second tensor
const t2 = [2, 5, 4];
  
// Calling meshgrid() function
const res = tf.meshgrid(t1, t2);
  
// Printing output
console.log(res);

輸出:

Tensor
    [[1, 1, 3],
     [1, 1, 3],
     [1, 1, 3]],Tensor
    [[2, 2, 2],
     [5, 5, 5],
     [4, 4, 4]]

範例2:使用浮點值。

Javascript


// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Calling meshgrid() function with
// float values
const output = tf.meshgrid(2.1, 3.3);
  
// Printing output
console.log(output);

輸出:

Tensor
     [[2.0999999],],Tensor
     [[3.3],]

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

相關用法


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