C5W1 Assignment 2: Model () adding lists

The highlighted parts, None for X and 0 for Y are not getting added to the list. This is what I am using
X = [None] + [single_example_ix]
Y = [single_example_ix] + [ix_newline]
How do I add None and 0(=\n) as one list?

Ok I was able to figure it out but now I am not using single_example_ix anyway to get X and then Y rather using [char_to_ix[c] for c in single_example_chars] and adding None before to it,

is this ok for submission? or are we expected to use single_example_ix to get X?

The instructions in section 3.2 contain this:

You can substitute None for ‘a’, and single_example_ix for [‘b’].

That’s what I used first and tried like single quotes etc but does not work, gives an error

IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices

Sometimes syntax errors as well

Tried multiple syntax but did not work so I used that.
I am new to Python and I am learning it on the fly either google search and/or recommendations made over here on Discourse.

And if you read my post again that’s exactly what I have done as you have recommended substituting for ‘a’ and ‘b’ but then it gives as shown highlighted in the original post with the error

only size-1 arrays can be converted to Python scalars

The error in my previous reply is for a different way of putting them together

Download your notebook and send it to me via a private message. I’ll take a look.

Hi, I have messaged you my notebook. Let me know what you think!
Thanks in advance
(Reading my posts from last night makes me sound like frustrated as hell lol sorry abt that I needed some sleep fs).

It’s funny sometimes how the same problem seems to crop up in multiple places at the same time. Here’s another parallel thread with a slightly different variation on this same problem.

The point in all of this is that you have to be really careful to understand the meaning of the syntax. If A is a list, then these two statements do not have the same effect:

B = [42] + A
C = [42] + [A]

Try it and see what happens. If len(A) is 4 a priori, then what do you think len(C) is? If you guessed 5, you’re in for a big surprise.

Here’s a worked example. Run the following code and watch what happens:

A = [1, 2, 3, 4]
print(type(A))
print(len(A))
B = [42] + A
print(B)
print(type(B))
print(len(B))
C = [42] + [A]
print(C)
print(type(C))
print(len(C))

You can insert a new cell to run the code by doing ‘Insert → Cell Below’.

If you’re new to python then you have to be careful: you can’t just assume you know what something does. You have to try it and examine the results. When things aren’t working, it probably means you’re misusing some piece of the syntax. The more useful approach is to stop and actually look at the results to understand what the meaning actually is, rather than just randomly trying things and getting frustrated.