Ruby 矩阵 row_count() 函数

Ruby 矩阵 row_count() 函数

row_count() 是Ruby中一个内置的方法,用于返回给定矩阵中的行数。

语法 :mat1.row_count()

参数 :该函数不需要任何强制参数。

返回值 :它返回矩阵中的行数。

例子 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

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程