I don’t know if there are other errors but you are not applying the right reshape
. Maybe you could check this post to improve your understanding of the reshape
function.
When using the reshape function you have to use two dimensions which make sense for the array you are working with.
Example:
a = np.array([0, 1, 2, 3, 4, 5])
# we can reshape the array to be a (3,2)
a.reshape(3, 2)
array([[0, 1],
[2, 3],
[4, 5]])
# when we use -1 the dimension is inferred so it makes sense
# for example if we put (2, -1) the dimension inferred will be 3
# so the array becomes (2, 3)
a.reshape(2, -1)
array([[0, 1, 2],
[3, 4, 5]])
The -1 is not to invert the array but rather to infer the missing value
[image]
If the array cannot be reshaped then you get an error, for example, the array a cannot be reshaped as (5, -1) because there is no number to be put in place of -1 that would allow the array to be reshaped:
>>> a = np.array([0, 1, 2, 3, 4, 5])
>>> a.reshape(5, -1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: cannot reshape array of size 6 into shape (5,newaxis)