A 2D array can be reshaped into a 1D array using .reshape(-1)
.
For example:
>>> a = numpy.array([[1, 2, 3, 4], [5, 6, 7, 8]])
>>> a.reshape(-1)
array([[1, 2, 3, 4, 5, 6, 7, 8]])
Usually, array[-1]
means the last element.
But what does -1 mean here?
check the below link for more info. https://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html
for the below example you mentioned the output explains the resultant vector to be a single row.(-1) indicates the number of rows to be 1. if the
output:
this can be explained more precisely with another example:
output:(is a 1 dimensional columnar array)
or
output:(is a 1 dimensional row array)