diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/zipf/SparseVector.rb | 9 | ||||
-rw-r--r-- | lib/zipf/fileutil.rb | 4 |
2 files changed, 13 insertions, 0 deletions
diff --git a/lib/zipf/SparseVector.rb b/lib/zipf/SparseVector.rb index 837403a..5d219b8 100644 --- a/lib/zipf/SparseVector.rb +++ b/lib/zipf/SparseVector.rb @@ -179,6 +179,15 @@ class SparseVector < Hash return new end + def / scalar + raise ArgumentError, "Arg is not numeric #{scalar}" unless scalar.is_a? Numeric + new = SparseVector.new + self.keys.each { |k| + new[k] = self[k] / scalar + } + return new + end + def self.mean a mean = SparseVector.new a.each { |i| diff --git a/lib/zipf/fileutil.rb b/lib/zipf/fileutil.rb index ac701da..7ae0c55 100644 --- a/lib/zipf/fileutil.rb +++ b/lib/zipf/fileutil.rb @@ -18,6 +18,10 @@ class ReadFile @f.gets { |line| yield line } end + def rewind + @f.rewind + end + def readlines @f.readlines end |