Related Articles

# Tensorflow.js tf.linalg.bandPart() Function

• Last Updated : 12 May, 2021

Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. It also helps the developers to develop ML models in JavaScript language and can use ML directly in the browser or in Node.js.

The tf.linalg.bandPart() function is used to calculate the band part of the given tensor.

Syntax:

`tf.linalg.bandPart (a, numLower, numUpper)`

Parameters:

• a: it is tf.tensor to be passed.
• numLower: Number of subdiagonals to keep. If negative, keep entire lower triangle
• numUpper: Number of subdiagonals to keep. If negative, keep entire upper triangle

Return Value: It returns tf.Tensor1D.

Example 1:

## Javascript

 `// Importing the tensorflow.js library``import * as tf from ``"@tensorflow/tfjs"`` ` `const x = tf.tensor2d([[ 0,  1,  2, 3],``                     ``[ 4,  0,  1, 2],``                     ``[ 3,  1,  0, 1],``                     ``[ 3,  1,  1, 0]]);`` ` `let y = tf.linalg.bandPart(x, 1, 3);``y.print();`

Output:

```Tensor
[[0, 1, 2, 3],
[4, 0, 1, 2],
[0, 1, 0, 1],
[0, 0, 1, 0]]```

Example 2:

## Javascript

 `// Importing the tensorflow.js library``import * as tf from ``"@tensorflow/tfjs"`` ` `const x = tf.tensor2d([[ 0,  1,  2, 3],``                     ``[ 4,  0,  1, 2],``                     ``[ 3,  1,  0, 1],``                     ``[ 3,  1,  1, 0]]);`` ` `let k = tf.linalg.bandPart(x, -1, -3);``k.print();`

Output:

```Tensor
[[0, 1, 2, 3],
[4, 0, 1, 2],
[3, 1, 0, 1],
[3, 1, 1, 0]]```

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it’s lowest price ever!

My Personal Notes arrow_drop_up