Home > other >  TypeError: uniform() got an unexpected keyword argument 'low'/'size'
TypeError: uniform() got an unexpected keyword argument 'low'/'size'

Time:06-08

visualizing a neural network result and this is what shows up:

def apply_net(y_in):
  global w, b

  z=dot(w, y_in) b
  return(1/(1 exp(-z)))

N0=2
N1=1 

w=random.uniform(low=-10,high= 10,size=(N1,N0)) # random weights: N1xN0
b=random.uniform(low=-1,high= 1,size=N1) #biases: N1 vector

TypeError Traceback (most recent call last) in () 2 N1=1 3 ----> 4 w=random.uniform(low=-10,high= 10,size=(N1,N0)) # random weights: N1xN0 5 b=random.uniform(low=-1,high= 1,size=N1) #biases: N1 vector

TypeError: uniform() got an unexpected keyword argument 'low'

___ If I remove low and high and keep it (-10, 10, size=(N1,N0)), it says: TypeError: uniform() got an unexpected keyword argument 'size'

If I remove size then it says: TypeError: uniform() takes 3 positional arguments but 4 were given

?

CodePudding user response:

must 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()

(figured it out and had to use this to solve the problem - note I ran it on colab)

CodePudding user response:

You must declare the alias library or the library name directly

        import numpy as np
        
        def apply_net(y_in):
          global w, b
        
          z=np.dot(w, y_in) b
          return(1/(1 np.exp(-z)))
        
        N0=2
        N1=1 
        
        w=np.random.uniform(low=-10,high= 10,size=(N1,N0)) # random weights: N1xN0
        b=np.random.uniform(low=-1,high= 1,size=N1) #biases: N1 vector
  • Related