简体   繁体   中英

Attribute error: “module 'numpy.random' has no attribute 'uniform' ”

Here are some of the things I tried to make it work I've tried searching for any file named random.py that I created (except for library files) and searched online for solutions like updating numpy but still can't find any decent solution. Here is my code:

from numpy import random
import random

#from random import uniform

#inputs- i.e population

equation_inputs = [4,-2,3.5,5,-11,-4.7]
 #number of weights 
num_weights = 6

sol_per_pop = 9

pop_size = (sol_per_pop,num_weights)
 #tuple of pop_size 

new_population = numpy.random.uniform(low=-4.0,high=4.0,size=pop_size)

The error message goes as follows

AttributeError: module 'numpy.random' has no attribute 'uniform'

I tried importing random and also

from numpy import random

The numpy.random.uniform should actually return 9 lists each with 6 solutions

Just use random.uniform while importing the related class with an alias (using 'as') or else just use import numpy while importing

An example for using alias is :

from numpy import random as np_random

Then utilize np_random.uniform()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM