loops in python - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: loops in python (/thread-5136.html) |
loops in python - nuncio - Sep-20-2017 This seems to be rather simple, but I am not getting there. I am trying to execute the math for Fourier transform. Here is the code I wrote import numpy as np x=[1,2,3,4] # my data values fn=np.arange(0,len(x),dtype=np.float) for k in fn: for xi in x: print(k) print(xi) xx=np.sum(xi*(np.exp(-1j*2.0*3.14*fn/len(x)))) print(xx)What I need id the sum for the x1,x2,x3,x4 when fn = 0 x1,x2,x3,x4 when fn=1 -------------- x1,x2,x3,x4 when fn=3 what I get instead is the sum as follows Appreciate any suggestions
RE: loops in python - gnanasekar - Sep-21-2017 In general, statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on. There may be a situation when you need to execute a block of code several number of times. Programming languages provide various control structures that allow for more complicated execution paths. A loop statement allows us to execute a statement or group of statements multiple times. The following diagram illustrates a loop statement − RE: loops in python - Sagar - Sep-21-2017 You have write second for loop inside sum() |