Ask Your Question

Using matrix for algebraic operation with its elements

asked 2017-06-18 16:45:27 -0500

pifko gravatar image


I would like to know if it's possible to use the matrix for algebraic calculations with its "individual" matrix elements. For example, i have matrix Z and i would like to logarithm each element, something like log(Z). Or do another algebraic operation with all elements separetly. What is the best practice?


edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted

answered 2017-06-19 02:32:44 -0500

mforets gravatar image

there is also apply_map:

sage: Z = random_matrix(ZZ, 5, x=1, y=10)
sage: Z.apply_map(lambda z : log(z))

[log(6)      0 log(6) log(2) log(8)]
[log(3) log(6) log(8) log(3) log(5)]
[log(6) log(9) log(5) log(4) log(6)]
[log(8) log(3) log(7) log(2) log(6)]
[     0      0 log(4) log(7) log(8)]
edit flag offensive delete link more

answered 2017-06-19 05:26:22 -0500

pifko gravatar image

Thank you both for the answer. Apply_map is a great feature. Thank you very much.

edit flag offensive delete link more


If you feel like that answer solved your problem, don't forget to click the "check mark" so that future visitors to this question will know it has a correct answer!

kcrisman gravatar imagekcrisman ( 2017-06-19 08:27:47 -0500 )edit

answered 2017-06-18 21:29:09 -0500

calc314 gravatar image

One approach is to use numpy arrays. For example...

import numpy as np
a = np.array([[1,e,3.3],[4.5,5.6,7.8]])
print log(a)
print np.log(a)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-06-18 16:45:27 -0500

Seen: 76 times

Last updated: Jun 19 '17