红宝石 |矩阵 column_count()函数
column_count()是 Ruby 中的一个内置方法,用于返回矩阵中的列数。
Syntax: mat1.column_count()
Parameters: The function does not accepts any parameter.
Return Value: It returns the number of columns in a matrix.
示例 1 :
# Ruby program for column_count() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[1, 21], [31, 18]]
# prints the number of columns
puts mat1.column_count
输出:
2
示例 2 :
# Ruby program for column_count() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[13, 1, 5], [12, 1, 5], [11, 2, 5]]
# prints the number of columns
puts mat1.column_count
输出:
3