Re: how to make this code faster

2005-10-14 Thread Tony Nelson
In article <[EMAIL PROTECTED]>, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > def f(x,y): > return math.sin(x*y) + 8 * x > I have code like this: > > def main(): > n = 2000 > a = zeros((n,n), Float) > xcoor = arange(0,1,1/float(n)) > ycoor = arange(0,1,1/float(n)) > > >

Re: how to make this code faster

2005-10-13 Thread George Sakkis
<[EMAIL PROTECTED]> 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(xc

Re: how to make this code faster

2005-10-13 Thread [EMAIL PROTECTED]
hello, I found that scipy only works with python 2.3 or? 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 hel

Re: how to make this code faster

2005-10-12 Thread Juho Schultz
[EMAIL PROTECTED] wrote: > def f(x,y): > return math.sin(x*y) + 8 * x > I have code like this: > > def main(): > n = 2000 > a = zeros((n,n), Float) > xcoor = arange(0,1,1/float(n)) > ycoor = arange(0,1,1/float(n)) > > > for i in range(n): > for j in range(n): >

Re: how to make this code faster

2005-10-12 Thread davbrow
It looks like you're using Numeric for your arrays, but you are then pulling sin from the math module and calculating one point at a time. Instead try using sin(whole array) where sin is a ufunc from the Numeric module. Also, it's usually not good practice to "import Numeric as *". Instead try im

Re: how to make this code faster

2005-10-12 Thread Robert Kern
[EMAIL PROTECTED] wrote: > def f(x,y): > return math.sin(x*y) + 8 * x > I have code like this: > > def main(): > n = 2000 > a = zeros((n,n), Float) > xcoor = arange(0,1,1/float(n)) > ycoor = arange(0,1,1/float(n)) > > > for i in range(n): > for j in range(n): >

how to make this code faster

2005-10-12 Thread [EMAIL PROTECTED]
def f(x,y): return math.sin(x*y) + 8 * x I have code like this: def main(): n = 2000 a = zeros((n,n), Float) xcoor = arange(0,1,1/float(n)) ycoor = arange(0,1,1/float(n)) for i in range(n): for j in range(n): a[i,j] = f(xcoor[i], ycoor[j]) # f(x,y) =