New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Matrix#exponentiate method as Matlab's exp method #1762
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like the idea 👍 I may choose a different name for the method 🤔
lib/matrix.rb
Outdated
@@ -1254,6 +1254,15 @@ def vstack(*matrices) | |||
self.class.vstack(self, *matrices) | |||
end | |||
|
|||
# | |||
# Returns a matrix with every entry being an exponent of e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about component
instead of entry
? 🤔
lib/matrix.rb
Outdated
# => Matrix[[2.718281828459045, 1.0], [1.0, 2.718281828459045]] | ||
|
||
def entrywise_exp | ||
collect{|e| Math.exp(e)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about calling the variable component
? e
is normally the letter used for the exponential and it may be confused.
lib/matrix.rb
Outdated
@@ -1254,6 +1254,15 @@ def vstack(*matrices) | |||
self.class.vstack(self, *matrices) | |||
end | |||
|
|||
# | |||
# Returns a matrix with every entry being an exponent of e | |||
# Matrix[[1, 0], [0, 1]].entrywise_exp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to add some spaces here this so it is interpreted as code
lib/matrix.rb
Outdated
# Matrix[[1, 0], [0, 1]].entrywise_exp | ||
# => Matrix[[2.718281828459045, 1.0], [1.0, 2.718281828459045]] | ||
|
||
def entrywise_exp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say it is not very explicit
@Ana06 Thanks for support! 😃 I've made changes according to what you pointed out. The name of the method was proposed at Ruby Redmine and I simply adopted it but if you've got better name I can change it. |
d8f0b4b
to
530514f
Compare
I prepared a pull request that includes exponentiate method which results in returning a new matrix with each element being an exponent of the number e. This is used e.g in machine learning and other types of calculations. #14116