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