Malik Ergin
Malik Ergin

Reputation: 1

How can I fix Runtime error for log in python

num_runs = 100000
p_values = []

for i in range(1, num_runs+1):
    ornek1 = 2*np.random.normal(0,1,5)
    ornek2 = 3*np.random.normal(0,2,5)
    ornek3 = 10*np.random.normal(0,5,5)
    

    
    levene = sp.levene(ornek1,ornek2,ornek3, center = 'mean')
    
    if levene[1] < 0.05:
    
        ornek1 = np.log10(ornek1)
        ornek2 = np.log10(ornek2)
        ornek3 = np.log10(ornek3)
        
    else: 
        continue
    
    anova = sp.f_oneway(ornek1,ornek2,ornek3)
    p_values.append(anova[1])
    
hesap = sum(map(lambda x: x<0.05, p_values))
print(hesap/100000)


RuntimeWarning: invalid value encountered in log10
  ornek1 = np.log10(ornek1)

How can I fix this problem ? I can't find anything. I want to transform my samples after levene test but ı can't. Is it about to numpy ?

Upvotes: 0

Views: 65

Answers (1)

Frank Yellin
Frank Yellin

Reputation: 11328

Just as a sample:

>>> np.random.normal(0, 1, 5)
array([ 1.68127583, -0.82660143, -1.82465141,  0.60495851, -0.90369304])

You're taking the log of negative numbers. What are you expecting to happen?

Upvotes: 1

Related Questions