Python Forum
'function' object does not support item assignment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
'function' object does not support item assignment
#1
Hi, I'm going to solve a nonlinear system of equations but I don't understand the error. Would you please help me what the problem is? Thank you very much.

[inline]
theta = 2.0
beta = 0.99
g = 0.005 
T = 5.0
delta = 0.2 
alpha1 = 0.33
alpha2 = 0.33
psi = 0.25
epsilon = 0.05
A0 = 0.1

def ss(z):
    
    x = z[0]
    m = z[1]
    k = z[2]
    b = z[3]
    L_x = z[4]
    L_b = z[5]
    r_k = z[6]
    r_b = z[7]
    w = z[8]
    A = z[9]
    I = z[10]
    
    ss[0] = x - m
    ss[1] = 1 + ((r_k-1) * (beta*psi-1)) / (beta * ((1-delta) + (1-r_k) *r_b *psi))
    ss[2] = b - (1-delta) * k + (1-delta)**T * I
    ss[3] = I - k + (1-delta) * k - (1-delta)**T * I
    ss[4] = (1-alpha1) * (x/L_x) - w
    ss[5] = alpha1 * (x/k) - r_k
    ss[6] = (1-alpha2) * (m/L_b) - w
    ss[7] = alpha2 * (m/b) - r_b
    ss[8] = L_x + L_b - 1
    ss[9] = A - A0 * (1+g)
    ss[10] = x + m + I - w - r_k*K - r_b*b
    
    return ss
    
z0 = [0.01, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]
z = fsolve(ss, z0)
    
print('Numerical x*', z[0])
print('Numerical m*', z[1])
print('Numerical k*', z[2])
print('Numerical b*', z[3])
print('Numerical L_x*', z[4])
print('Numerical L_b*', z[5])
print('Numerical r_k*', z[6])
print('Numerical r_b*', z[7])
print('Numerical w*', z[8])
print('Numerical A*', z[9])
print('Numerical I*', z[10])
[/inline]
Error:
'function' object does not support item assignment
Reply
#2
Post entire error message!
And enough code to recreate problem
Reply
#3
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-17-150efdede077> in <module>()
     39 
     40 z0 = [0.01, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]
---> 41 z = fsolve(ss, z0)
     42 
     43 print('Numerical x*', z[0])

E:\Anaconda3\lib\site-packages\scipy\optimize\minpack.py in fsolve(func, x0, args, fprime, full_output, col_deriv, xtol, maxfev, band, epsfcn, factor, diag)
    144                'diag': diag}
    145 
--> 146     res = _root_hybr(func, x0, args, jac=fprime, **options)
    147     if full_output:
    148         x = res['x']

E:\Anaconda3\lib\site-packages\scipy\optimize\minpack.py in _root_hybr(func, x0, args, jac, col_deriv, xtol, maxfev, band, eps, factor, diag, **unknown_options)
    210     if not isinstance(args, tuple):
    211         args = (args,)
--> 212     shape, dtype = _check_func('fsolve', 'func', func, x0, args, n, (n,))
    213     if epsfcn is None:
    214         epsfcn = finfo(dtype).eps

E:\Anaconda3\lib\site-packages\scipy\optimize\minpack.py in _check_func(checker, argname, thefunc, x0, args, numinputs, output_shape)
     24 def _check_func(checker, argname, thefunc, x0, args, numinputs,
     25                 output_shape=None):
---> 26     res = atleast_1d(thefunc(*((x0[:numinputs],) + args)))
     27     if (output_shape is not None) and (shape(res) != output_shape):
     28         if (output_shape[0] != 1):

<ipython-input-17-150efdede077> in ss(z)
     24     I = z[10]
     25 
---> 26     ss[0] = x - m
     27     ss[1] = 1 + ((r_k-1) * (beta*psi-1)) / (beta * ((1-delta) + (1-r_k) *r_b *psi))
     28     ss[2] = b - (1-delta) * k + (1-delta)**T * I

TypeError: 'function' object does not support item assignment
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  What is the mechanism of numpy function returning pandas object? Ibaraki 2 2,497 Apr-04-2020, 10:57 PM
Last Post: Ibaraki

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020