diff options
Diffstat (limited to 'lib/nlp_ruby/SparseVector.rb')
-rw-r--r-- | lib/nlp_ruby/SparseVector.rb | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/nlp_ruby/SparseVector.rb b/lib/nlp_ruby/SparseVector.rb index a4e2bce..6843b70 100644 --- a/lib/nlp_ruby/SparseVector.rb +++ b/lib/nlp_ruby/SparseVector.rb @@ -42,6 +42,10 @@ class SparseVector < Hash return sum end + def zeros n + (0).upto(n-1) { |i| self[i] = 0.0 } + end + def magnitude Math.sqrt self.values.inject { |sum,i| sum+i**2 } end |