HomeLanguagesJavascriptTensorflow.js tf.layers.repeatVector() Function

Tensorflow.js tf.layers.repeatVector() Function

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.

The tf.layers.repeatVector() function is used to repeat the input n number of times in a new specified dimension. It is an inbuilt function of TensorFlow’s.js library.

Syntax:

tf.layers.repeatVector(n)

Parameters:

  • n: Integer, specifying the number of times the input will be repeated.

Return value: It returns the tf.layers.Layer

Example 1:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
    
  
// Create a new model
const model = tf.sequential();
    
// Add repeatVector layer to the model
model.add(tf.layers.repeatVector({
    n: 5, inputShape: [2]}
));
    
const x = tf.tensor2d([[10, 15]]);
   
console.log(model.predict(x).shape)


Output:

1, 5, 2

Example 2:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
    
// Create a new model
const model = tf.sequential();
    
// Add repeatVector layer to the model
model.add(tf.layers.repeatVector(
      {n: 8, inputShape: [2]}
));
   
const x = tf.tensor2d([[0,1]]);
   
model.predict(x).print();


Output:

Tensor
    [[[0, 1],
      [0, 1],
      [0, 1],
      [0, 1],
      [0, 1],
      [0, 1],
      [0, 1],
      [0, 1]]]

Reference: https://js.tensorflow.org/api/latest/#layers.repeatVector

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
Previous article
Next article
RELATED ARTICLES

3 COMMENTS

Most Popular

Dominic
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7447 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS