Ask Your Question

Replace all numbers < e-n by 0

asked 2020-06-06 11:38:15 +0200

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)

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


The short name for SageMath that everyone uses is Sage.

slelievre gravatar imageslelievre ( 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...

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

The default assumption on 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 07:52:07 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2020-06-06 12:53:28 +0200

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


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 16:47:29 +0200 )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


Asked: 2020-06-06 11:38:15 +0200

Seen: 395 times

Last updated: Jun 06 '20