# Replace all numbers < e-n by 0

As always two question in one.

F = random_matrix(RR,7,50)
import numpy as np
covMatrix = np.cov(F,bias=True)
Ω=matrix(covMatrix)
Λ=Ω.inverse()
Ω*Λ


1) Is there a way to ask Sama (nicname for SAgeMAth more elegant than SM -- a wink) to overcome the number less than e-n and replace it by 0 --- I have found a way : to use change_ring(QQ) but I want to know if therre is another way. 2) is there a way to ask Sama to display only n decimal digit.

edit retag close merge delete

The short name for SageMath that everyone uses is Sage.

( 2020-06-06 14:52:37 +0200 )edit

Yes but this is from a time where Sagemath was named Sage --- I think the name has been changed because of the accounting software. But if I must comply I will nod snif...

( 2020-06-06 17:44:34 +0200 )edit

The default assumption on ask.sagemath.org is that Sage refers to SageMath, not to any other Sage.

See also William Stein's original post introducing the long name "SageMath", from which this is an excerpt:

The actual command name and "sage:" prompt wouldn't change, and we would still call it "sage" in discussions, emails, etc.

( 2020-06-12 07:52:07 +0200 )edit

Sort by » oldest newest most voted

The apply_map method allows to apply a given map to any entry of the matrix, here you can replace any small number by zero:

sage: M = Ω*Λ
sage: M.apply_map(lambda x : 0 if abs(x) <10^-15 else x)


You can also directly use:

sage: M.round()

more

tmonteil thanks to answer allways to my questions. I should have been able to answer to it myself if i have found a list off all Sage commands. round()seems so easy. But I have not found this list. On the contrary I found it for numpy or simpy.

( 2020-06-06 16:47:29 +0200 )edit