Skip to content

Instantly share code, notes, and snippets.

Created July 27, 2011 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/1109434 to your computer and use it in GitHub Desktop.
Save anonymous/1109434 to your computer and use it in GitHub Desktop.
require 'narray'
class 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(self, 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)t
matrix = matrix.reshape(1, matrix.total)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment