Wednesday, May 27, 2026
HomeLanguagesJavascriptTensorflow.js tf.tile() Function

Tensorflow.js tf.tile() Function

TensorFlow.js is a library for machine learning in JavaScript. It helps developers to develop ML models in JavaScript, and use ML directly in the browser or in Node.js.

The tf.tile() function is used to create a Tensor by repeating the number of times given by reps.

Syntax:

tf.tile(x, reps)

Note: This function creates a new tensor by replicating the input reps times. For example, tiling [1, 2, 3, 4] by [3] produces [1, 2, 3, 4,1, 2, 3, 4,1, 2, 3, 4].

 

Parameter: This function accepts the following two parameters.

  • x: The tensor passed to the tile. It can be tf.Tensor, TypedArray, or Array.
  • reps: This parameter defines the number of replications per dimension.

Return: It returns tf.Tensor object.

Example 1:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Creating a tensor1d
const a = tf.tensor1d([1, 2, 3, 4]);
  
// Creating the tensor with the help of tile()
const x = a.tile([2]);
  
// Printing the tensor
x.print();


Output:

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

Example 2:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Creating a tensor2d
const a = tf.tensor2d([1, 2, 3, 4, 5, 6],[2, 3]);
  
// Creating the tensor with the help of tile()
const x = a.tile([1,2]);
  
// Printing the tensor
x.print();


Output:

Tensor
   [[1, 2, 3, 1, 2, 3],
    [4, 5, 6, 4, 5, 6]]

Example 3:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
  
// Creating a tensor2d
const a = tf.tensor2d([1, 2, 3, 4, 5, 6],[2, 3]);
  
// Creating the tensor with the help of tile()
const x = a.tile([3,2]);
  
// Printing the tensor
x.print();


Output:

Tensor
   [[1, 2, 3, 1, 2, 3],
    [4, 5, 6, 4, 5, 6],
    [1, 2, 3, 1, 2, 3],
    [4, 5, 6, 4, 5, 6],
    [1, 2, 3, 1, 2, 3],
    [4, 5, 6, 4, 5, 6]]

Reference: https://js.tensorflow.org/api/latest/#tile

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!
RELATED ARTICLES

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6892 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12107 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS