Let's say I have a square matrix with 20 lines and 20 columns. Using NumPy, what should I do to transform this matrix into a 1D array with a single line and 400 columns (that is, 20.20 = 400, all in one line)?
So far, I've tried:
1) array = np.ravel(matrix)
2) array = np.squeeze(np.asarray(matrix))
But when I print array, it's still a square matrix.
array = matrix.flatten()matrix.reshape(-1,)np.reshape()it should work(more detail [docs.scipy.org/doc/numpy/reference/generated/…).array = matrix.ravel()should work if matrix is an ndarray.raveldoesn't work, then there's something unusual aboutmatrix. Tell us itsshape,dtype, and whether it isnp.matrixor not.