From: Stefan Behnel on 30 Jan 2010 14:28 uche, 30.01.2010 20:18: > I got another problem after changing / to // . Yes, I am using 3.1. > > W.append(exp(sign * 2j * pi * i // N)) > TypeError: can't take floor of complex number. Don't change it everywhere, just where it deals with integers. In the above, "/" is perfectly right. Stefan
From: uche on 30 Jan 2010 14:30 On Jan 30, 2:21 pm, Stefan Behnel <stefan...(a)behnel.de> wrote: > Stefan Behnel, 30.01.2010 19:52: > > > uche, 30.01.2010 19:33: > >> I have the following FFT python code > > > You didn't seriously implement an FFT in plain Python code, did you? > > Sorry, no, you didn't. Should have read your post a little closer. > > > FFTs > > are amongst the first thing that come to my mind when I try to imagine what > > I'd use NumPy for. (and I *never* used it!) > > On second thought, I'd probably use FFTW for that, and there seem to be > Python bindings for it: > > http://developer.berlios.de/projects/pyfftw/ > > Stefan Thanks for the suggestions and site. I just wanted to know what the heck is going wrong with this code. Please take a look at the code , thanks
From: uche on 30 Jan 2010 15:20 On Jan 30, 2:30 pm, uche <uraniumore...(a)gmail.com> wrote: > On Jan 30, 2:21 pm, Stefan Behnel <stefan...(a)behnel.de> wrote: > > > > > > > Stefan Behnel, 30.01.2010 19:52: > > > > uche, 30.01.2010 19:33: > > >> I have the following FFT python code > > > > You didn't seriously implement an FFT in plain Python code, did you? > > > Sorry, no, you didn't. Should have read your post a little closer. > > > > FFTs > > > are amongst the first thing that come to my mind when I try to imagine what > > > I'd use NumPy for. (and I *never* used it!) > > > On second thought, I'd probably use FFTW for that, and there seem to be > > Python bindings for it: > > >http://developer.berlios.de/projects/pyfftw/ > > > Stefan > > Thanks for the suggestions and site. I just wanted to know what the > heck is going wrong with this code. Please take a look at the code , > thanks- Hide quoted text - > > - Show quoted text - Thanks Stephan. You are the best! Another issue: x[a], x[b] = x[(a)] + W[(n % N)] * x[(b)], x[(a)] - W[(n % N)] * x [(b)] TypeError: can't multiply sequence by non-int of type 'complex'
From: Mark Dickinson on 31 Jan 2010 05:02 On Jan 30, 8:20 pm, uche <uraniumore...(a)gmail.com> wrote: > Another issue: > x[a], x[b] = x[(a)] + W[(n % N)] * x[(b)], x[(a)] - W[(n % N)] * x > [(b)] > TypeError: can't multiply sequence by non-int of type 'complex' With your original code, the elements of array2 are strings, and here Python is refusing to multiply the string x[a] by the complex number W [n % N]. Presumably you want the elements of array2 to be integers or floats instead? (Your comments suggest integers, though I think floats would be more natural here.) MRAB's earlier reply suggests how to fix this: array2 = [] for a in range(len(array)): array2.append(int(array[a])) # note the extra int! That works, but the code is cleaner if you iterate over the elements of the array directly, instead of over their indices: array2 = [] for x in array: array2.append(int(x)) There are other ways, too: a seasoned Python user would probably write this either as a list comprehension: array2 = [int(x) for x in array] .... or using the built-in map function: array2 = map(int, array) -- Mark
From: Mark Dickinson on 31 Jan 2010 05:07 On Jan 31, 10:02 am, Mark Dickinson <dicki...(a)gmail.com> wrote: > Python is refusing to multiply the string x[a] by the complex number W > [n % N]. Whoops, that should have been "x[b]", not "x[a]". Why is it that a post-submission proofread turns up errors so much more often than a pre-submission proofread? -- Mark
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: C API: module cleanup function Next: pyjon: pythonic javascript interpreter |