Ask Your Question

why using numpy

asked 2013-10-25 15:33:45 +0200

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

what is the advantage of using numpy arrays, matrices, integers, floats, ..etc. over the normal ones in sage ??

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2013-10-26 09:04:19 +0200

tmonteil gravatar image

updated 2013-10-26 09:21:15 +0200

As you can see in the list of standard packages, numpy is included in Sage, but is only a small part of it. Hence Sage is much more versatile than numpy. In particular, a number has more representations in Sage than in numpy. For example, if you want to deal with floating-point approximations of real numbers, in Sage you have the choice between RealDoubleField, RealField and RealIntervalField, so there is no "normal one". The first one (corresponding to machine doubles), is very close to numpy.float64, so there will not be much difference in this case. But there is no equivalent of RealField or RealIntervalField in numpy.

Basically, for a given task, Sage makes choices among available softwares. So, when numpy is the most appropriate, it will be used transparently. This is the case for dense matrices over RealDoubleField, so even in this case (numpy is a specialist in matrices), you do not have to specifically use numpy since Sage does it for you.

That said, the choice is more important between Sage representations than between a Sage representaton and its numpy equivalent (when it exists). For example, some computations are much faster in matrices over RealDoubleField than over RealField(53). Also, the computation of eignevalues over RealDoubleField is more accurate than the naive algorithm over RealField.

However, Sage is monolithic and much bigger than numpy, hence, it may be suitable to use numpy if you plan to distribute your piece of software as a standalone application.

edit flag offensive delete link more


thank you so much for your reply. The problem is that i am dealing with very large numbers that exceed the ranges fro numpy integers and doubles, so i have to use sage.

Mohamed Gaafar gravatar imageMohamed Gaafar ( 2013-11-04 05:23:26 +0200 )edit

Yep. The length of Sage integers is only limited by your memory.

tmonteil gravatar imagetmonteil ( 2013-11-04 05:25:33 +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


Asked: 2013-10-25 15:33:45 +0200

Seen: 914 times

Last updated: Oct 26 '13