0

When i run this code to create my function

def create_theoretical(list1 = [], zvalues = []):
 
  list_of_values = []
  h_1 = list1[0]
  omega_m1 = list1[1] 
  omega_l1 = list1[2]
 
  for z in zvalues:
    list_of_values.append(mu(z = z, h =h_1, omega_m = omega_m1, omega_l = omega_l1))
  list_of_values = np.asarray(list_of_values)

  return list_of_values  
    

I get this error

 10 
     11   list_of_values = []
---> 12   h_1 = list1[0]
     13   omega_m1 = list1[1]
     14   omega_l1 = list1[2]

TypeError: 'function' object is not subscriptable

If i switch list1 and zvalues, then the error comes for zvalues. if i put another preceding argument in the function the error goes away, but i dont want to pass anymore arguments. How do i resolve this? If i call

print(type(list1)) 

or

print(type(zvalues))

then the output first says that the type is a numpy array, then it says its a function. Why does the type change?

d.p
  • 3
  • 2
  • 2
    Show your full code. somewhere you redefine `list1` to be a function. – buran Mar 10 '21 at 09:19
  • and by the way - don't use mutable default arguments. Check https://stackoverflow.com/questions/1132941/least-astonishment-and-the-mutable-default-argument – buran Mar 10 '21 at 09:20
  • We need to see the code where you use `create_theoretical()`. You pass an argument there and we need to see the variable definition of that first parameter. – Thomas Weller Mar 10 '21 at 09:21

0 Answers0