-
-
Save serialhex/1109437 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'narray' | |
def LoadMatrix(filename, type = :numbers) | |
case type | |
when :numbers | |
LoadMatrix.load_numbers(filename) | |
when :dna | |
LoadMatrix.load_dna(filename) | |
when :cubes | |
LoadMatrix.load_cubes(filename) | |
when :labels | |
LoadMatrix.load_labels(filename) | |
end | |
end | |
module LoadMatrix | |
def load_numbers(filename) | |
matrix = [] | |
File.open(filename) do |file| | |
file.each_line do |line| | |
ary = [] | |
line.split(" ").each{ |n| ary << n.to_f } | |
matrix << ary | |
end | |
end | |
matrix = NArray.to_na(matrix) | |
matrix = matrix.transpose | |
end | |
def load_dna(filename) | |
matrix=[] | |
File.open(filename) do |file| | |
file.each_line do |line| | |
line.split("\n").each{|n| matrix << n } | |
end | |
end | |
matrix | |
end | |
def load_cubes(filename) | |
matrix=[] | |
File.open(filename) do |file| | |
file.each_line do |line| | |
line.split("\n").each{|n| matrix << n } | |
end | |
end | |
matrix | |
end | |
def load_labels(filename) | |
matrix = [] | |
File.open(filename) do |file| | |
file.each_line do |line| | |
ary = [] | |
line.split(" ").each{ |n| ary << n.to_f } | |
matrix << ary | |
end | |
end | |
matrix = NArray.to_na(matrix) | |
matrix = matrix.reshape(1, matrix.total) | |
end | |
extend self | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment