Added Matrix.random
This commit is contained in:
parent
8e8a72345c
commit
20bd6423d9
|
@ -89,6 +89,11 @@ module Apatite
|
|||
Matrix.empty(row_count, column_count)
|
||||
end
|
||||
|
||||
# Creates a matrix of the given shape with random vectors.
|
||||
def random_matrix(row_count, column_count, range = nil)
|
||||
Matrix.random(row_count, column_count, range)
|
||||
end
|
||||
|
||||
# Creates a matrix where the diagonal elements are composed of `values`.
|
||||
def diagonal(values)
|
||||
Matrix.diagonal(values)
|
||||
|
|
|
@ -108,6 +108,13 @@ module Apatite::LinearAlgebra
|
|||
scalar(n, 1)
|
||||
end
|
||||
|
||||
# Creates a matrix of the given shape with random vectors.
|
||||
def self.random(num_rows, num_columns, range = nil)
|
||||
Matrix.build(num_rows, num_columns) do |i, j|
|
||||
rand(range || -1e+1..1e+1)
|
||||
end
|
||||
end
|
||||
|
||||
# Creates a single-row matrix where the values of that row are as given in `row`.
|
||||
def self.row_vector(row)
|
||||
Matrix.new([row], 0)
|
||||
|
|
Loading…
Reference in New Issue