TypeError: f_of_omega() takes 1 positional argument but 3 were given


TypeError Traceback (most recent call last)
Cell In [76], line 1
----> 1 w1_unittest.test_f_of_omega(f_of_omega)

File ~/work/w1_unittest.py:195, in test_f_of_omega(target_f_of_omega)
171 test_cases = [
172 {
173 “name”: “default_check”,
(…)
191 },
192 ]
194 for test_case in test_cases:
→ 195 result = target_f_of_omega(test_case[“input”][“omega”], test_case[“input”][“pA”], test_case[“input”][“pB”])
197 try:
198 assert result.shape == test_case[“expected”][“f_of_omega”].shape

TypeError: f_of_omega() takes 1 positional argument but 3 were given

1 Like

Hi @fariiha12.
Welcome to the community.
Your error is due to the arguments you supplied in the f_of_omega function. Kindly go through it again and try. I’m sure you can resolve it.

1 Like

You’ve posted in the Week 2 forum area, but your question regards the Week 1 programming assignment. I’ll move the thread to the correct area.

I believe the error “f_of_omega() takes 1 positional argument” indicates that you may be using an old copy of the programming assignment notebook.

Can you say from where you got your copy of the notebook file?

w1_unittest.test_f_of_omega(f_of_omega) how i can solve this problem

What problem are you having specifically?
A screen capture image would be helpful.

TypeError: f_of_omega() takes 1 positional argument but 3 were given

1 Like

I suspect you either have an old copy of the notebook ipynb file, or you have an old copy of one of the .py utility files.

The fix is to use the Files menu in the notebook, and rename those files. then use the Help menu to “Get latest version”.

Then you can start over on the assignment.

2 Likes

thanks a lot i solve it but 3exercise difficult for me

Parameter endpoint=True will allow ending point 1 to be included in the array.

This is why it is better to take N = 1001, not N = 1000

N = 1001
omega_array = np.linspace(0, 1, N, endpoint=True)

This is organised as a function only for grading purposes.

def L_of_omega_array(omega_array, pA, pB):
N = len(omega_array)
L_array = np.zeros(N)

for i in range(N):
    ### START CODE HERE ### (~ 2 lines of code)
    L = None(None[None], None, None)
    L_array = L_array.at[None].set(None)
    ### END CODE HERE ###
    
return L_array

L_array = L_of_omega_array(omega_array, prices_A, prices_B)
how to solve it

1 Like

You need to fill in two lines of code, replacing the “None” text with the correct code.

For the first line:

  • You replace the first None with the correct function name. Hint: It’s the function that computes “L of omega”.
  • That function accepts three arguments. The first None is an array name, the next None is that array’s index. The last two Nones are that function’s other arguments.

For the second line:

  • You replace the first None with an index variable.
  • You replace the second None with the the variable name that was returned by the first line (see above).
2 Likes

L =L of omega(omega_array[i], None, None) what about two none
L_array = L_array.at[i].set(L)

1 Like

I recommend you read the function definition for L_of_omega(). That will tell you what parameters it expects.

how did you solve this? please i need help

This kind of error is usually caused by using an obsolete copy of either the notebook ipynb file, or the python unit test utility file.

1 Like

How do I reset the notebook to start again from the beginning?

1 Like

Instructions are in the “M4ML Resources FAQ” thread. You can find it using the forum Search tool.

1 Like