Movatterモバイル変換


[0]ホーム

URL:


Menu
×
See More 
Sign In
+1 Get Certified Upgrade Teachers Spaces Bootcamps Get Certified Upgrade Teachers Spaces Bootcamps
   ❮     
     ❯   

Tensors

A Tensor is aN-dimensional Matrix:

  • A Scalar is a 0-dimensional tensor
  • A Vector is a 1-dimensional tensor
  • A Matrix is a 2-dimensional tensor

ATensor is a generalization ofVectors andMatrices to higher dimensions.

ScalarVector(s)
1
1
2
3
 
123

MatrixTensor
123
456
 
123
456
 
456
123
 

Tensor Ranks

The number of directions a tensor can have in aN-dimensional space, is called theRank of the tensor.

The rank is denotedR.

AScalar is a single number.

  • It has 0 Axes
  • It has aRank of 0
  • It is a 0-dimensional Tensor

AVector is an array of numbers.

  • It has 1 Axis
  • It has aRank of 1
  • It is a 1-dimensional Tensor

AMatrix is a 2-dimensional array.

  • It has 2 Axis
  • It has aRank of 2
  • It is a 2-dimensional Tensor

Real Tensors

Technically, all of the above are tensors, but when we speak of tensors, we generally speak of matrices with a dimension larger than 2 (R > 2).

Tensor

Linear Algebra in JavaScript

In linear algebra, the most simple math object is theScalar:

const scalar = 1;

Another simple math object is theArray:

const array = [ 1, 2, 3 ];

Matrices are2-dimensional Arrays:

const matrix = [ [1,2],[3,4],[5,6] ];

Vectors can be written asMatrices with only one column:

const vector = [ [1],[2],[3] ];

Vectors can also be written asArrays:

const vector = [ 1, 2, 3 ];

Tensors areN-dimensional Arrays:

const tensor = [ [1,2,3],[4,5,6],[7,8,9] ];

JavaScript Tensor Operations

Programming tensor operations in JavaScript, can easily become a spaghetti of loops.

Using a JavaScript library will save you a lot of headache.

One of the most common libraries to use for tensor operations is calledtensorflow.js.

Tensor Addition

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

// Tensor Addition
const tensorAdd = tensorA.add(tensorB);

// Result [ [2, 1], [5, 2], [8, 3] ]

Try it Yourself »

Tensor Subtraction

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

// Tensor Subtraction
const tensorSub = tensorA.sub(tensorB);

// Result [ [0, 3], [1, 6], [2, 9] ]

Try it Yourself »

Learn more about Tensorflow ...



×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness
of all content. While using W3Schools, you agree to have read and accepted ourterms of use,cookies andprivacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved.W3Schools is Powered by W3.CSS.

-->
[8]ページ先頭

©2009-2026 Movatter.jp