当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Ruby Matrix 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


相关用法


注:本文由纯净天空筛选整理自gopaldave大神的英文原创作品 Ruby | Matrix row_count() function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。