Tensorflow.js tf.transpose() 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.
The tf.transpose() function is used to perform a regular matrix transpose operation on the specified 2-D input tensor.
Syntax:
tf.transpose (x)
Parameters: This function accepts a parameter which is illustrated below:
- x: The specified input tensor to transpose.
Return Value: It returns a tensor as the output for the transpose operation.
Example 1:
Javascript
import * as tf from "@tensorflow/tfjs"
const a = tf.tensor2d([2, 4, 6, 8], [2, 2]);
a.transpose().print();
|
Output:
Tensor
[[2, 6],
[4, 8]]
Example 2:
Javascript
import * as tf from "@tensorflow/tfjs"
tf.tensor2d([1, 3, 5, 7, 9, 11], [2, 3]).transpose().print();
tf.tensor2d([1, 3, 5, 7, 9, 11], [3, 2]).transpose().print();
|
Output:
Tensor
[[1, 7 ],
[3, 9 ],
[5, 11]]
Tensor
[[1, 5, 9 ],
[3, 7, 11]]
Reference: https://js.tensorflow.org/api/latest/#transpose
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...