SciRuby / daru

Data Analysis in RUby
BSD 2-Clause "Simplified" License
1.03k stars 139 forks source link

Can two vector with numbers combine without nil? #361

Closed MitsunChieh closed 7 years ago

MitsunChieh commented 7 years ago

In https://github.com/SciRuby/daru/blob/master/lib/daru/maths/arithmetic/vector.rb#L65

Two vectors with same index can be added. But if one vector has the index and the other one doesn't, it will return nil. Can some other methods just set the nil value as zero, so that they can be added?

zverok commented 7 years ago

@MitsunChieh What's your usecase? Even being the author of the comment in the method, it is hard for me currently to imagine an abastract situation :)

v0dro commented 7 years ago

Maybe you can replace the nil values with 0 in the resulting vector using replace_nils.

http://www.rubydoc.info/gems/daru/0.1.5/Daru/Vector#replace_nils-instance_method