why using numpy

asked 2013-10-25 08:33:45 -0500 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 close merge delete

Sort by » oldest newest most voted

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.

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.

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