Exercise 4 in C2_W1_Assignment

I am getting an IndexError: tuple index out of range (please see below).

I am setting the dLdOmega by calling the grad function with the L_of_omega_array function and evaluating at omega_array[i].

I have very poor vision temporarily and I may be missing something obvious. Also, I think I already posted about this question, but I can not find the pot under my profile.


IndexError Traceback (most recent call last)
File /opt/conda/lib/python3.8/site-packages/jax/core.py:1427, in ShapedArray._len(self, ignored_tracer)
1426 try:
→ 1427 return self.shape[0]
1428 except IndexError as err:

IndexError: tuple index out of range

The above exception was the direct cause of the following exception:

TypeError Traceback (most recent call last)
Cell In [18], line 24
21 print(“end of loop”)
22 return dLdOmega_array
—> 24 dLdOmega_array = dLdOmega_of_omega_array(omega_array)

Cell In [18], line 15, in dLdOmega_of_omega_array(omega_array)
12 # dLdOmega = None(None)(None[None])
13 # dLdOmega_array = dLdOmega_array.at[None].set(None)
14 print(omega_array[i])
—> 15 dLdOmega = …
16 print(type(ddLdOmega))
17 dLdOmega_array = …

[... skipping hidden 10 frame]

Cell In [14], line 8, in L_of_omega_array(omega_array)
7 def L_of_omega_array(omega_array):
----> 8 N = len(omega_array)
9 L_array = np.zeros(N)
11 for i in range(N):
12 ### START CODE HERE ### (~ 2 lines of code)
13 # L = None(None[None])
14 # L_array = L_array.at[None].set(None)

[... skipping hidden 1 frame]

File /opt/conda/lib/python3.8/site-packages/jax/core.py:1429, in ShapedArray._len(self, ignored_tracer)
1427 return self.shape[0]
1428 except IndexError as err:
→ 1429 raise TypeError(“len() of unsized object”) from err

TypeError: len() of unsized object

Hello @rtayek I really didn’t understand your question but please check out this thread if it will help

I did find any clues there.

has anyone gotten this part to work?


Look at the ‘hint’ that is provided in the assignment. You are using the wrong function as input into grad.

hit works great. thank you