diff options
author | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-11-20 02:18:43 +0000 |
---|---|---|
committer | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-11-20 02:18:43 +0000 |
commit | c1a0a09d2b7fb920640857d4ed4b48761b94fb86 (patch) | |
tree | ee92df24c9e490fdc44947e52e10d6e0cc0a4a42 /lib | |
parent | a2061a5d56534cf22fdbe9a9d43e967a2cd9ebe3 (diff) | |
download | ruby-c1a0a09d2b7fb920640857d4ed4b48761b94fb86.tar.gz |
lib/matrix: Add hadamard_product/entrywise_product.
Based on a patch by Charley Hutchison. [GH-674]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60860 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/matrix.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/matrix.rb b/lib/matrix.rb index 2f2d0f371a..d242665ef9 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -980,6 +980,17 @@ class Matrix end # + # Hadamard product + # Matrix[[1,2], [3,4]].hadamard_product(Matrix[[1,2], [3,2]]) + # => 1 4 + # 9 8 + # + def hadamard_product(m) + combine(m){|a, b| a * b} + end + alias_method :entrywise_product, :hadamard_product + + # # Returns the inverse of the matrix. # Matrix[[-1, -1], [0, -1]].inverse # => -1 1 |