Ask Your Question
0

Replace all numbers < e-n by 0

asked 2020-06-06 04:38:15 -0500

Cyrille gravatar image

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 flag offensive close merge delete

Comments

The short name for SageMath that everyone uses is Sage.

slelievre gravatar imageslelievre ( 2020-06-06 07:52:37 -0500 )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...

Cyrille gravatar imageCyrille ( 2020-06-06 10:44:34 -0500 )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.

slelievre gravatar imageslelievre ( 2020-06-12 00:52:07 -0500 )edit

1 answer

Sort by » oldest newest most voted
0

answered 2020-06-06 05:53:28 -0500

tmonteil gravatar image

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()
edit flag offensive delete link more

Comments

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.

Cyrille gravatar imageCyrille ( 2020-06-06 09:47:29 -0500 )edit

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

Stats

Asked: 2020-06-06 04:38:15 -0500

Seen: 42 times

Last updated: Jun 06