Week 2, exercise 5

Hi,

I don’t know why my code is not working:

# (≈ 1 line of code)
# v =
# YOUR CODE STARTS HERE
v=v.reshape(image.shape[0] * image.shape[1] *3, 1)

# YOUR CODE ENDS HERE

return v

I am getting this error:

UnboundLocalError Traceback (most recent call last)
in
12 [ 0.34144279, 0.94630077]]])
13
—> 14 print ("image2vector(image) = " + str(image2vector(t_image)))
15
16 image2vector_test(image2vector)

in image2vector(image)
13 # v =
14 # YOUR CODE STARTS HERE
—> 15 v=v.reshape(image.shape[0] * image.shape[1] *3, 1)
16
17 # YOUR CODE ENDS HERE

UnboundLocalError: local variable ‘v’ referenced before assignment

Can someone please help me?

If you look at the error output, it says:
UnboundLocalError: local variable ‘v’ referenced before assignment

You’re trying to call v.reshape(), which the variable v does not exist yet.

yes, but if try to change code like this:
v=image
v=v.reshape(image.shape[0] * image.shape[1] *3, 1)

i am getting this errorValueError: cannot reshape array of size 18 into shape (27,1)

so i am not sure how to initialize v

I solved the problem, thanks

Great! Yes, the problem is that you hard-coded one of the dimensions to 3, instead of using the actual value.