Ruby 矩阵 row_size() 函数
row_size() 是Ruby中一个内置的方法,用于返回给定矩阵中的行数。
语法 : mat1.row_size()
参数 :该函数不需要任何强制参数。
返回值 : 它返回矩阵中的行数。
例子 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