選單
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

TensorFlow 操作

  • 方形
  • 重塑形狀

張量加法

您可以使用 tensorA.add(tensorB) 將兩個張量相加

示例

const tensorA = tf.tensor([[1, 2], [3, 4], [5, 6]]);
const tensorB = tf.tensor([[1,-1], [2,-2], [3,-3]]);

// 張量加法
const tensorNew = tensorA.add(tensorB);

// 結果: [ [2, 1], [5, 2], [8, 3] ]

自己動手試一試 »


張量減法

您可以使用 tensorA.sub(tensorB) 來減去兩個張量

示例

const tensorA = tf.tensor([[1, 2], [3, 4], [5, 6]]);
const tensorB = tf.tensor([[1,-1], [2,-2], [3,-3]]);

// 張量減法
const tensorNew = tensorA.sub(tensorB);

// 結果: [ [0, 3], [1, 6], [2, 9] ]

自己動手試一試 »



張量乘法

您可以使用 tensorA.mul(tensorB) 將兩個張量相乘

示例

const tensorA = tf.tensor([1, 2, 3, 4]);
const tensorB = tf.tensor([4, 4, 2, 2]);

// 張量乘法
const tensorNew = tensorA.mul(tensorB);

// 結果: [ 4, 8, 6, 8 ]

自己動手試一試 »


張量除法

您可以使用 tensorA.div(tensorB) 來除以兩個張量

示例

const tensorA = tf.tensor([2, 4, 6, 8]);
const tensorB = tf.tensor([1, 2, 2, 2]);

// 張量除法
const tensorNew = tensorA.div(tensorB);

// 結果: [ 2, 2, 3, 4 ]

自己動手試一試 »


張量平方

您可以使用 tensor.square() 來計算張量的平方

示例

const tensorA = tf.tensor([1, 2, 3, 4]);

// 張量平方
const tensorNew = tensorA.square();

// 結果 [ 1, 4, 9, 16 ]

自己動手試一試 »


張量重塑

張量中的元素數量是形狀中各尺寸的乘積。

由於具有相同尺寸的形狀可能不同,因此通常需要將張量重塑為具有相同尺寸的其他形狀。

您可以使用 tensor.reshape() 來重塑張量

示例

const tensorA = tf.tensor([[1, 2], [3, 4]]);
const tensorB = tensorA.reshape([4, 1]);

// 結果: [ [1], [2], [3], [4] ]

自己動手試一試 »


×

聯絡銷售

如果您想將 W3Schools 服務用於教育機構、團隊或企業,請傳送電子郵件給我們
sales@w3schools.com

報告錯誤

如果您想報告錯誤,或想提出建議,請傳送電子郵件給我們
help@w3schools.com

W3Schools 經過最佳化,旨在方便學習和培訓。示例可能經過簡化,以提高閱讀和學習體驗。教程、參考資料和示例會不斷審查,以避免錯誤,但我們無法保證所有內容的完全正確性。使用 W3Schools 即表示您已閱讀並接受我們的使用條款Cookie 和隱私政策

版權所有 1999-2024 Refsnes Data。保留所有權利。W3Schools 由 W3.CSS 提供支援