# C5_W1_Assig2_Ex4 model()

Ex_4_v4 error.pdf (81.0 KB)

Hi,

I am puzzled with this error:
‘only size -1 arrays can be converted to Python scalars’
pointing to a sentence of the test.

I cannot figure out the instance that originate it. I suspected could be X and Y, but all I have tried did not work. Could you give me a hint of its origin?

I have also a doubt with the shifting of Y, Should we to consider leading [None] position of X as part of its length or not.

Can you upload the document here as an image? I’m not likely to open a mysterious PDF file.

Hi@TMosh

Sorry, I did not realize

Thks

The problem is that your X and Y values are lists containing other lists, but they should be simple lists. For comparison, here’s what I see from that same section:

``````j =  0 idx =  0
single_example = turiasaurus
single_example_chars ['t', 'u', 'r', 'i', 'a', 's', 'a', 'u', 'r', 'u', 's']
single_example_ix [20, 21, 18, 9, 1, 19, 1, 21, 18, 21, 19]
X =  [None, 20, 21, 18, 9, 1, 19, 1, 21, 18, 21, 19]
Y =        [20, 21, 18, 9, 1, 19, 1, 21, 18, 21, 19, 0]

Iteration: 0, Loss: 23.087336

Nkzxwtdmfqoeyhsqwasjkjvu
Kneb
Kzxwtdmfqoeyhsqwasjkjvu
Neb
Zxwtdmfqoeyhsqwasjkjvu
Eb
Xwtdmfqoeyhsqwasjkjvu
``````

See the difference? Your X is a list containing two elements: the first is None and the second is a list containing 11 elements. My X is a simple list containing 12 elements. So how did that happen?

1 Like

Yes, I suspected it from the description, but I tried ravel() and Flatten() without results, and as the error points to the test I got stuck.

Your words and examples brought me to the correct track again. Building X and Y with np.hstack solved the question but I imagine that there are many more ways of solving the problem.

Many Thanks
joansitges