how to make this code faster

George Sakkis gsakkis at rutgers.edu
Thu Oct 13 10:15:43 EDT 2005


<ajikoe at gmail.com> wrote:

> hello,
>
> I found that scipy only works with python 2.3 or?

You can use Numeric instead of scipy if you need/want to:

from Numeric import arange,reshape,sin

def computeMatrix(n):
    xcoor = arange(0,1,1/float(n))
    ycoor = reshape(xcoor, (n,1))
    return sin(xcoor*ycoor) + 8*xcoor

Note that arange() does not include the endpoint, i.e. arange(0,1,0.25).tolist() ==[0.0, 0.25, 0.5,
0.75].

> I don't know if the logic is correct:
> 1. loop inside loop uses a lot of resources
> 2. Numeric or Numpy can make program faster
> 3. It use kind of Array/Matrix analysis style
> 4. We have to change our algorithms so that Numeric or Numpy can help
> us, Matrix style

That's correct more or less.

George





More information about the Python-list mailing list