简体   繁体   English

属性错误:“module'numpy.random'没有属性'uniform'”

[英]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. 以下是我尝试使其工作的一些事情我已经尝试搜索我创建的任何名为random.py的文件(库文件除外)并在线搜索更新numpy等解决方案但仍无法找到任何合适的解决方案。 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' AttributeError:模块'numpy.random'没有属性'uniform'

I tried importing random and also 我尝试random导入也

from numpy import random

The numpy.random.uniform should actually return 9 lists each with 6 solutions numpy.random.uniform实际上应该返回9个列表,每个列表有6个解决方案

Just use random.uniform while importing the related class with an alias (using 'as') or else just use import numpy while importing 只需使用random.uniform导入带有别名的相关类(使用'as')或者只是在导入时使用import numpy

An example for using alias is : 使用别名的示例是:

from numpy import random as np_random

Then utilize np_random.uniform() 然后利用np_random.uniform()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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