I have been using odient in python for a project and it's been working completely fine. I did the same thing I always do for this problem and for some reason it keeps saying my defined function takes 1 positional argument but 2 were given, even though it's been fine doing problems like this before. Here is my code:
def sy(J):
Ntot=J[0]
xb=J[1]
dNtotdt=nn2-nv
dxbdt=(-nv*xb-xb*dNtotdt)/Ntot
return[dNtotdt,dxbdt]
#odeint requires that we set up a vector of times (question asks for 0-10)
t_val=np.linspace(0,10,46) #46 for more accuracy
#we also need to make an initial condition vector
Yo=np.array([Ntoto,xbo])
#use odient function to find the concentrations
ans=odeint(sy,Yo,t_val)
print(ans)
please help
your derivative function passed to odeint needs to expect 2 inputs (y and t), the most straight forward solution is to just make your function take multiple arguments as you seem to have forgotten.
def sy(J,t):
In the error it clearly mentioned that the function "Odient" takes 1 positional argument but you are trying to put more than 1 argument example.
#This function take one Parameter "var"
def foo(var):
return var
#Calling the function with print statement
print(foo(var, var2)) #Trying to give more than 1 argument. But it gives error
Like this you are doing with your code.
Related
In my unit test case, I'm trying to check if a particular function is being called or not using this:
mock_wait_until_complete.assert_called()
The function wait until complete takes 2 arguments: (uid: string, time: int)
I want to build it in such a way that it passes the test case irrespective of any arguments that are passed.
Is there any way to achieve this?
** Edit
AssertionError:
Expected call: wait_until_complete('bt_url, verify=False)
Actual call: wait_until_complete(<MagicMock name='post().text' id='2039952'>)
So, right now I'm getting this error with this piece of code during testing, but its working exactly how I want it to. So, to basically ignore this error, I want it to accept/assert True no matter what argument is being passed..
In addition to the comments, I solved this particular code by using:
assertEqual(mocked_wait_until_complete.call_count, 1)
This basically checks if the function is called once irrespective of any arguments passed.
I have a function which takes 1 argument. The function outputs several results and assigns them to a variable for later use. I would like to change the variable names using the argument but I am unsure how to do so. What I envison is something like what I have written below, but this returns a syntax error and I am not sure where to go from here.
Thank you!
def Get_Sums_Counts(Category):
{Category}_Total_Count = len(Analyzed_Month[Analyzed_Month['age_cat'] == Category])
return {Category}_Total_Count
{Category}_Total_Sum = round(Analyzed_Month[Analyzed_Month['age_cat'] == Category].sum())
return {Category}_Total_Sum
I am getting this error while working on question 4 (Chapter 2) from the "Hands on Machine learning" book. This is the question "Try creating a single pipeline that does the full data preparation plus the final prediction". The solution is available in Github link, but the solution is giving me the error mentioned in the title. I used the housing data for my example. Please help me.
I wrote this command and it fired the following error:
prepare_select_and_predict_pipeline = Pipeline([
('preparation', full_pipeline),
('feature_selection', TopFeatureSelector(feature_importances, k)),
('svm_reg', SVR(**rnd_search.best_params_))
])
prepare_select_and_predict_pipeline.fit(housing,housing_labels)
Error:
TypeError: fit() takes 2 positional arguments but 3 were given
I would like to attach the solution from Github
Solution of Question 2 from Github
But this isn't working for me. :(
Warning, I'm going to grossly simplify here, but I hope this will help.
In Python, if you call a function on an object, the object itself is always passed as the first argument (unless it is a static or class method). This is usually captured by a parameter we call self.
So, if you call object.function(), you are passing an argument to function, namely object itself.
class C:
def f(self):
print(self)
o = C()
o.f() # <__main__.C object at 0x7f1049993f28>
o.f('hello') # TypeError: f() takes 1 positional argument but 2 were given
In your case, you are calling prepare_select_and_predict_pipeline.fit(housing, housing_labels), so you are passing the function fit three arguments: prepare_select_and_predict_pipeline, housing and housing_labels.
If you check the definition of the fit method, you will probably find that it indeed only takes two arguments. I'm guessing the first one will be called self.
so this is my function, and it doesn't work.. why?
def Oppnadjur(djurfil):
djurfil = open("djur.txt", "r")
Djur = djurfil.readlines()
Djur.sort()
djurfil.close()
Djurlista=[]
You wrote that your function should receive one parameter, djurfil. However, you clearly did not mean to do that, as you proceed to not use that parameter, overwriting it with a different value. See the Python Tutorial about how to define functions.
The error message you see means that you had called your function as you had intended, with no parameters (Opnnadjur()), but that's not how you had defined it. So Python is looking for the parameter it thinks you should be passing in.
The error would be in your calling code, not the def of the function. You need to call Oppnadjur with one parameter. The error message suggests that you are calling it with zero parameters.
You define your function with one argument (djurfil), but the argument is unused in your function so you can get rid of it.
def Oppnadjur():
djurfil = open("djur.txt", "r")
Djur = djurfil.readlines()
Djur.sort()
djurfil.close()
Djurlista=[]
I'm currently using singpath.com to practice my python, but I face an issue with a problem:
The expected result is:
>>>CurryPuff(3)
3.60
>>>CurryPuff(3,'Fish')
4.2
This is something I tried:
def CurryPuff(x,typePuff):
if(typePuff==''):
return x*1.2
if(typePuff=='Fish'):
return x*1.4
But it give me this error:
TypeError: CurryPuff() takes exactly 2 arguments (1 given)
I had try googling on this but I'm not really very sure what is the key word to use, so hopefully can get help from here.
Thanks.
You can't call a function with 1 argument if it expects 2, as CurryPuff() does. However, you can define a default argument that is used if no argument is passed:
def CurryPuff(x, typePuff=None):
if typePuff is None:
# and so on...
You can do this with any value for any argument. You may only omit arguments if a default value is defined.