column()是Ruby中的内置方法,它返回一个向量,该向量具有列号col_num中的所有元素。
用法: mat1.column(col_num)
参数:该函数接受参数col_num,它是列号。
返回值:它返回一个包含列col_num的所有元素的向量。
例子1:
# Ruby program for column() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[1, 21], [31, 18]]
# Prints the value of mat1.column
puts mat1.column(1)
输出:
Vector[21, 18]
例子2:
# Ruby program for column() method in Matrix
# Include matrix
require "matrix"
# Initialize a matrix
mat1 = Matrix[[13, 1, 5], [12, 1, 5], [11, 2, 5]]
# Prints the value of mat1.column
puts mat1.column(1)
输出:
Vector[1, 1, 2]
相关用法
- Ruby Matrix row()用法及代码示例
- Ruby Matrix det()用法及代码示例
- Ruby Matrix tr()用法及代码示例
- Ruby Matrix zero?()用法及代码示例
- Ruby Matrix inv()用法及代码示例
- Ruby Matrix eql?用法及代码示例
- Ruby Matrix lup()用法及代码示例
- Ruby Matrix zero()用法及代码示例
- Ruby Matrix I()用法及代码示例
- Ruby Matrix t()用法及代码示例
- Ruby Matrix orthogonal?用法及代码示例
- Ruby Matrix column_size()用法及代码示例
- Ruby Matrix minor()用法及代码示例
- Ruby Matrix singular?()用法及代码示例
- Ruby Matrix normal?用法及代码示例
注:本文由纯净天空筛选整理自gopaldave大神的英文原创作品 Ruby | Matrix column() function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。