红宝石 |矩阵 row_count()函数
row_count()是 Ruby 中的一个内置方法,它返回给定矩阵中的行数。
Syntax: mat1.row_count()
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_count() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[6, 432], [54, 323]]
# Prints the number of rows
puts mat1.row_count()
输出:
2
示例 2 :
# Ruby program for row_count() 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_count()
输出:
3