Tensorflow.js是Google開發的開源庫,用於在瀏覽器或節點環境中運行機器學習模型和深度學習神經網絡。
tf.sparseToDense()函數用於將指定的稀疏表示形式轉換為密集的Tensor。如果給定索引重複出現,則將最終值累加到該索引的所有值上。
用法:
tf.sparseToDense(sparseIndices, sparseValues, outputShape, defaultValue)
參數:該函數接受四個參數,如下所示:
- sparseIndices:它是數據類型為int32的0-D,1-D或2-D張量。這裏,sparseValues [i]放在sparseIndices [i]上,其中i是索引值。
- sparseValues:它是與sparseIndices的每一行相對應的0-D或1-D Tensor值。
- outputShape:它是轉換後的密集輸出張量的形狀。
- defaultValue:它是為未在sparseIndices中指定的索引設置的值。其默認值為零。它是一個可選參數。
範例1:
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Initializing indices and values
const indices = tf.tensor1d([4, 3, 2, 1, 0], 'int32');
const values = tf.tensor1d([1111, 111, 11, 1, 0.1], 'float32');
// Specifying shape for the output dense
const shape = [7];
// Getting the Dense representation for the above
// sparse representation
tf.sparseToDense(indices, values, shape).print();
輸出:
Tensor [0.1, 1, 11, 111, 1111, 0, 0]
範例2:
Javascript
// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
// Initializing indices and values
const indices = tf.tensor1d([1, 2, 3], 'int32');
const values = tf.tensor1d([10, 20, 30], 'float32');
// Getting the Dense representation for the above
// sparse representation along with shape of [6]
// and default value of 55
tf.sparseToDense(indices, values, [6], 55).print();
輸出:
Tensor [55, 10, 20, 30, 55, 55]
相關用法
- PHP imagecreatetruecolor()用法及代碼示例
- p5.js year()用法及代碼示例
- d3.js d3.utcTuesdays()用法及代碼示例
- PHP ImagickDraw getTextAlignment()用法及代碼示例
- PHP Ds\Sequence last()用法及代碼示例
- PHP Imagick floodFillPaintImage()用法及代碼示例
- PHP array_udiff_uassoc()用法及代碼示例
- PHP geoip_continent_code_by_name()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- PHP GmagickPixel setcolor()用法及代碼示例
- PHP opendir()用法及代碼示例
- PHP cal_to_jd()用法及代碼示例
- d3.js d3.bisectLeft()用法及代碼示例
- PHP stream_get_transports()用法及代碼示例
- PHP Ds\Deque pop()用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 Tensorflow.js tf.sparseToDense() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。