[Numpy-discussion] The problem with arrays
Fabrice Silva
silva@lma.cnrs-mrs...
Tue Sep 22 12:53:40 CDT 2009
Le mardi 22 septembre 2009 à 23:00 +0530, yogesh karpate a écrit :
> This is the main thing . When I try to store it in array like
> R_time=array([R_t[0][i]]). It just stores the final value in that
> array when loop ends.I cant get out of this For loop.I really have
> this small problem. I really need help on this guys.
>
> for i in range(a1):
> data_temp=(bpf[left[0][i]:
> right[0][i]])# left is an array and right is also an array
> maxloc=data_temp.argmax() #taking indices of
> max. value of data segment
> maxval=data_temp[maxloc]
> minloc=data_temp.argmin()
> minval=data_temp[minloc]
> maxloc = maxloc-1+left # add offset of present
> location
> minloc = minloc-1+left # add offset of present
> location
> R_index = maxloc
> R_t = t[maxloc]
> R_amp = array([maxval])
> S_amp = minval#%%% Assuming the S-wave is the lowest
> #%%% amp in the given window
> #S_t = t[minloc]
> R_time=array([R_t[0][i]])
> plt.plot(R_time,R_amp,'go');
> plt.show()
Two options :
- you define an empty list before the loop
>>> R_time = []
and you append the computed value while looping
>>> for i:
>>> ...
>>> R_time.append(t[maxloc])
- or you define a preallocated array before the loop
>>> R_time = np.empty(a1)
and fill it with the computed values
>>> for i:
>>> ...
>>> R_time[i] = t[maxloc]
Same thing with R_amp. After looping, whatever the solution you choose,
you can plot the whole set of (time, value) tuples
>>> plt.plot(R_time, R_amp)
--
Fabrice Silva <silva@lma.cnrs-mrs.fr>
LMA UPR CNRS 7051
More information about the NumPy-Discussion
mailing list