mercredi 6 avril 2022

Runtime error: Overflow encountered in double scalars. How do I solve this?

I am trying to generate 500 numbers each from a uniform distribution over the intervals [-Kmin^N,Kmin] and [Kmax,Kmax^N].

Following is the code that I used:

Kmin=min(K1[0],K1[1],K1[2],K1[3],K1[4])  
Kmax=max(K1[0],K1[1],K1[2],K1[3],K1[4]) 
K3=np.zeros(500)
K4=np.zeros(500)
d=0
#the new weights
W_tilde=np.zeros(5)
while d<5:
    c=0
    total=0
    while c<500:
       #generating uniform random numbers from the sets [-Kmin^N,Kmin] and [Kmax,Kmax^N]
        K3[c]=Kmax+(Kmax**N-Kmax)*random.uniform(0,1)
        K4[c]=(-Kmin**N)+(Kmin+Kmin**N)*random.uniform(0,1)
        total=total+(K3[c]+K4[c])*W2[d]
        c=c+1
    W_tilde[d]=total/N
    d=d+1

However, I am getting the following error in the output.

<ipython-input-4-257ed5a3bfee>:70: RuntimeWarning: overflow encountered in double_scalars
  K3[c]=Kmax +((Kmax**N) -Kmax)*random.uniform(0,1)
<ipython-input-4-257ed5a3bfee>:71: RuntimeWarning: overflow encountered in double_scalars
  K4[c]=-(Kmin**N) +(Kmin+(Kmin**N))*random.uniform(0,1)
<ipython-input-4-257ed5a3bfee>:71: RuntimeWarning: invalid value encountered in double_scalars
  K4[c]=-(Kmin**N) +(Kmin+(Kmin**N))*random.uniform(0,1)

Can someone please tell me where I went wrong?




Aucun commentaire:

Enregistrer un commentaire