You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, thanks for your work on this great Ruby gem!
On one of my recent projects, I needed to multiply all the elements of my NArray. I searched the documentation, hoping to find an equivalent to the .sum method, but it seems to me there is none. I think it would be useful to have such a method included in the NArray library. Below I will paste the solution I used, extending the narray class and converting to a ruby array and finally multiplying the elements:
# Multiplies all elements in the array and returns the resulting number:
class NArray
def multiply
self.to_a.inject(:*)
end
end
a = NArray[2,3,7]
a.sum
=> 12
a.multiply
=> 42
Best regards,
Chris
The text was updated successfully, but these errors were encountered:
First of all, thanks for your work on this great Ruby gem!
On one of my recent projects, I needed to multiply all the elements of my NArray. I searched the documentation, hoping to find an equivalent to the .sum method, but it seems to me there is none. I think it would be useful to have such a method included in the NArray library. Below I will paste the solution I used, extending the narray class and converting to a ruby array and finally multiplying the elements:
Best regards,
Chris
The text was updated successfully, but these errors were encountered: