Python Error :'numpy.float64' object is not callable - python

I have written a code in python to generate a sequence of ARIMA model's and determine their AIC values to compare them.The code is as below,
p=0
q=0
d=0
for p in range(5):
for d in range(1):
for q in range(4):
arima_mod=sm.tsa.ARIMA(df,(p,d,q)).fit()
print(arima_mod.params)
print arima_mod.aic()
I am getting a error message as below,
TypeError Traceback (most recent call last)
<ipython-input-60-b662b0c42796> in <module>()
8 arima_mod=sm.tsa.ARIMA(df,(p,d,q)).fit()
9 print(arima_mod.params)
---> 10 print arima_mod.aic()
global arima_mod.aic = 1262.2449736558815
11
**TypeError: 'numpy.float64' object is not callable**

Remove the brackets after print arima_mod.aic(). As I read it, arima_mod.aic is 1262.2449736558815, and thus a float. The brackets make python think it is a function, and tries to call it. You do not want that (because it breaks), you just want that value. So remove the brackets, and you'll be fine.

Related

I am getting ValueError: list.remove(x): x not in list on my code

code_arr=[]
for i in word_tokenize(student_code):
code_arr.append(i)
print(code_arr)
print(len(code_arr))
codet_arr=[]
for i in word_tokenize(teacher_code):
codet_arr.append(i)
print(codet_arr)
print(len(codet_arr))
for code_s in code_arr:
for code_t in codet_arr:
if code_s==code_t:
code_arr.remove(code_t)
else:
continue
The above code gives below error:
ValueError Traceback (most recent call last)
<ipython-input-13-4fe8ea0c7232> in <module>()
2 for code_t in codet_arr:
3 if code_s==code_t:
----> 4 code_arr.remove(code_t)
5 else:
6 continue
ValueError: list.remove(x): x not in list
Without knowing the content of the arrays it's difficult to duplicate but I suspect your problem is in modifying the content of an array that you're iterating over.
For clarity, I tend to build a set of values that I want to remove, then remove them in a separate loop, viz...
to_remove = set()
for code_s in code_arr:
for code_t in codet_arr:
if code_s == code_t:
to_remove.add(code_t)
for code in to_remove:
code_arr.remove(code)
Debugging is easier too as you can check the codes to be removed before removing them.
Ps. You don't need the 'else continue' on the end of a loop.
I think this will work :
for i in code_arr:
while i in code_t:
code_t.remove(i)
print(code_t)

Unable to Access last end value in a range of list

I want to access large range value as this higher end value will be change sometimes as I couldnt able to print last value, If I give lower range it is getting printed but when I give higher range like 73138176 or more than 7 digits it is getting memory error,as I am using Python 2.7.10, can anyone help me to get print the value of last range in this version of Python
lbas_on_bank = []
start=0
end=73138176
for lba in range(start,end):
if len(lbas_on_bank)>50:
lbas_on_bank = []
else:
lbas_on_bank.append(lba)
last_written_lba = lbas_on_bank[-1]
print(last_written_lba)
output:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
MemoryError
Use xrange() instead of range()
Or
try:
your code..
except MemoryError as er:
print(er)

Python : Slice each sentence in list of sentences

I am trying to slice each sentence in a list of sentences from [0:10] character of it.
Example of list of sentences: list name = sd_list
['I was born and brought up in Delhi.',
'I am using Dell Latitude E5140 laptop since 2012.',
'I work for ABC company since 2014.']
I tried to slice the first 10 characters of each sentence by running the below code and failed.
sent10 = [s[0:10] for s in sd_list]
By running this I encountered below TypeError
TypeError Traceback (most recent call last)
in ()
----> 1 [s[0:10] for s in sd_list]
in (.0)
----> 1 [s[0:10] for s in sd_list]
TypeError: 'float' object is not subscriptable
--> I even tried defining a function :
def sent_slice(text):
for s in range(0,len(text)):
text[s] = text[s][0:10]
return text
sent_slice(sd_list)
TypeError Traceback (most recent call last)
in ()
----> 1 sent_slice(sd_list)
in sent_slice(text)
1 def sent_slice(text):
2 for s in range(0,len(text)):
----> 3 text[s] = text[s][0:10]
4 return text
TypeError: 'float' object is not subscriptable
Could someone help me understand this "TypeError: 'float' object is not subscriptable" . How can I achieve my goal of slicing sentence?
it means that you have a float in sd_list. you can find it by doing something like:
print([f for f in sd_list if isinstance(f, float)])

Basic in Python

I'd like to write a basic program which copy the content from variable 'a' to variable 'b' but in reverse order, e.g.: a="toy" to b="yot"
My code:
a="toy"
index= len(a)
indexm=0
new=" "
while(index>0):
new[indexm]==a[index]
index=index-1
indexm=indexm+1
print(new)
I've got the following error message:
IndexError: string index out of range
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-56-c909e83737f5> in <module>()
5
6 while(index>0):
----> 7 new[indexm]==a[index]
8 index=index-1
9 indexm=indexm+1
IndexError: string index out of range
I would like to solve it without using built-in functions to learn programmer thinking.
Thank you in advance
try this:
a="toy"
index= len(a)
indexm=0
new=""
while(index>0):
new += a[index-1]
index=index-1
indexm=indexm+1
print(new)

fminbound for a simple equation

def profits(q):
range_price = range_p(q)
range_profits = [(x-c(q))*demand(q,x) for x in range_price]
price = range_price[argmax(range_profits)] # recall from above that argmax(V) gives
# the position of the greatest element in a vector V
# further V[i] the element in position i of vector V
return (price-c(q))*demand(q,price)
print profits(0.6)
print profits(0.8)
print profits(1)
0.18
0.2
0.208333333333
With q (being quality) in [0,1], we know that the maximizing quality is 1. Now the question is, how can I solve such an equation? I keep getting the error that either q is not defined yet (which is only natural as we are looking for it) or I get the error that some of the arguments are wrong.
q_firm = optimize.fminbound(-profits(q),0,1)
This is what I've tried, but I get this error:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-99-b0a80dc20a3d> in <module>()
----> 1 q_firm = optimize.fminbound(-profits(q),0,1)
NameError: name 'q' is not defined
Can someone help me out? If I need to supply you guys with more information to the question let me know, it's my first time using this platform. Thanks in advance!
fminbound needs a callable, while profits(q) tries to calculate a single value. Use
fminbound(lambda q: -profits(q), 0, 1)
Note that the lambda above is only needed to generate a function for negative profits. Better define a function for -profits and feed it to fminbound.
Better still, use minimize_scalar instead of fminbound.

Categories