Open In App

Ruby | Matrix t() function

Improve
Improve
Like Article
Like
Save
Share
Report

The t() is an inbuilt method in Ruby returns the transpose of the matrix.

Syntax: mat1.t()

Parameters: The function needs the matrix to be transposed.

Return Value: It returns the transposed matrix.

Example 1:




# Ruby program for t() method in Matrix
  
# Include matrix 
require "matrix"
  
# Initialize a matrix 
mat1 = Matrix[[3, 12], [2, 8]]  
  
# Prints the transpose matrix
puts  mat1.t()


Output:

Matrix[[3, 2], [12, 8]]

Example 2:




# Ruby program for t() method in Matrix
   
# Include matrix 
require "matrix"
   
# Initialize a matrix 
mat1 = Matrix[[1, 0], [6, 1], [1, 2]]  
   
# Prints the transpose matrix
puts  mat1.t()


Output:

Matrix[[1, 6, 1], [0, 1, 2]]

Last Updated : 07 Jan, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads