红宝石 |矩阵 row_size()函数
row_size()是 Ruby 中的一个内置方法,它返回给定矩阵中的行数。
Syntax: mat1.row_size()
Parameters: The function does not takes any mandatory parameter.
Return Value: It returns the number of rows in the matrix.
示例 1 :
# Ruby program for row_size() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[6, 432], [54, 323]]
# Prints the number of rows
puts mat1.row_size()
输出:
2
示例 2 :
# Ruby program for row_size() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[1, 1, 1],[2, 2, 2],[3, 5, 6]]
# Prints the number of rows
puts mat1.row_size()
输出:
3