How does one perform the exp() operation element-wise in Juila?

前端 未结 3 1501
醉话见心
醉话见心 2021-01-20 22:24

I\'m new to Julia and this seems like a straight-forward operation but for some reason I am not finding the answer anywhere.

I have been going through some tutorials

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-20 23:07

    In julia, operations on matrices treat the matrix as an object rather than a collection of numbers. As such exp(A) tries to perform the matrix exponential which is only defined for square matrices. To get element-wise operations on matrices, you use broadcasting which is done with the dot operator. Thus here, you want exp.(A).

    This design is used because it allows any scalar operation to be done on arrays rather than just the ones built in to the language.

提交回复
热议问题