Home > Blockchain >  python for loop no results
python for loop no results

Time:09-23

I made a for loop but it does not show any error and results.

What can I do to see the results (plots)?

below is the code

    for n in range(10, 10, 100):
 88     print(n)
 89     lowcut=float(1/(n 3))
 90     highcut=float(1/(n-3))
 91     # BPF
 92     yy = butter_bandpass_filter(z, lowcut, highcut, Fs, order=2)
 93     #GW
 94     yy1 = butter_bandpass_filter(GW, lowcut, highcut, Fs, order=2)
 95     #CC
 96     npts=len(yy)
 97     lags = np.arange(-npts   1, npts)
 98     ccov = np.correlate(yy - yy.mean(), yy1 - yy1.mean(), mode='full')
 99     ccor = ccov / (npts * yy.std() * yy1.std())
100     fig, axs = plt.subplots(nrows=2)
101     fig.subplots_adjust(hspace=0.4)
102     #Upper Graph
103     ax = axs[0]
104     ax.plot(date, yy, 'b', label='dv/v')
105     ax.plot(date, yy1, 'r', label='GW')
106     ax.set(title="{}".format(n) "day")
107     ax.legend(loc='upper right', fontsize='small', ncol=2)
108     #Lower Graph
109     ax = axs[1]
110     ax.plot(lags, ccor)
111     ax.set_ylim(-1, 1)
112     ax.set_ylabel('cross-correlation')
113     ax.set_xlabel('lag of dv/v relative to GW')
114     maxlag = lags[np.argmax(ccor)]
115     ax.set(title="Cross-Correlation \n max correlation is" " {}".format(round(np.max(ccor), 3)) " at lag %d day" % maxlag)
116     plt.show()

117

CodePudding user response:

I found the solution with the help of all of you.

Thank you so much.

I made the range variation because when I made (10, 100, 10), it showed raise ValueError("Digital filter critical frequencies " ValueError: Digital filter critical frequencies must be 0 < Wn < 1 (error related to butter_bandpass), but (10, 10, 100) showed nothing.

After I saw the replies, I tried to find the solutions in other parts and succeed.

for n in range(10, 100, 10):
 88     print(n)
 89     lowcut = float(1 / float(n 3))
 90     highcut = float(1 / float(n-3))

If I do not make the lowcut and highcut, the both values become 0.0 and give the value error.

Thank you again!

CodePudding user response:

A range works like:

range(start, end, step)

You wrote:

for n in range(10, 10, 100):

if a loop starts a 10 and ends at 9, the loop won't execute at all.

What Can You Do

if you want do loop from 10 to 100 with a step of 10, do

for n in range(10, 101, 10)

end is 101 cause I assume you want 100 in your loop

  • Related