Tensorflow.js是Google開發的開源庫,用於在瀏覽器或節點環境中運行機器學習模型和深度學習神經網絡。
tf.zeros()函數用於創建所有元素都設置為零的新張量。
用法:
tf.zeros(shape, dataType)
參數:
- shape:它采用我們將要生成的張量的形狀。
- dataType:它是結果元素中張量的類型。它可以是“ float32”,“ int32”或‘bool’。默認為“float32”值。它是一個可選參數。
返回值:它返回給定形狀的張量,所有元素都設置為零。
範例1:在此示例中,我們使用tf.zeros()創建形狀為1 * 1的張量。
Javascript
// Importing the tensorflow.Js lbrary
import * as tf from "@tensorflow/tfjs"
// Creating a shape variable
// which stores the shape
var shape = [1,1]
// Creating the tensor
var val = tf.zeros(shape)
// Printing the tensor
val.print()
輸出:
Tensor [[0],]
範例2:在此示例中,我們使用tf.zeros()和dataType參數創建形狀為2 * 2的張量。
Javascript
// Importing the tensorflow.Js lbrary
import * as tf from "@tensorflow/tfjs"
// Creating a shape variable
// which stores the shape
var shape = [2, 2]
// Creating a d_Type variable
// which strores the data-type
var d_Type = 'bool'
// Creating the tensor
var val = tf.zeros(shape, d_Type)
// Printing the tensor
val.print()
輸出:
Tensor [[false, false], [false, false]]
範例3:在此示例中,我們使用tf.zeros()創建形狀為1 * 1的張量。
Javascript
// Importing the tensorflow.Js lbrary
import * as tf from "@tensorflow/tfjs"
// Creating a shape variable
// which stores the shape
var shape = [3,3]
// Creating the tensor
var val = tf.zeros(shape)
// Printing the tensor
val.print()
輸出:
Tensor [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
相關用法
- 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()用法及代碼示例
- PHP SimpleXMLElement children()用法及代碼示例
注:本文由純淨天空篩選整理自121910316053大神的英文原創作品 Tensorflow.js tf.zeros() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。