Reputation: 351
In linear algebra, vectors are normalized when they are divided by their norm, that is, the squared sum of their components.
Yet, sklearn.preprocessing.normalize method does not accept vectors, only matrices of at least two columns:
"ValueError: Expected 2D array, got 1D array instead"
Why?
Upvotes: 1
Views: 529
Reputation: 3053
According to the documentation for sklearn.preprocessing.normalize
, the parameter x
is the data to normalize, element by element, and has the shape [n_samples, n_features]. The function normalize
perform this operation on a single array-like dataset, either using the L1 or L2 norms.
Upvotes: 0
Reputation: 77827
normalize
works on a data set, not a vector. You have the wrong definition of "normalize" for this function. It works on individual vectors. If you give it a 2D array of a single column (shape of [N, 1]), you can get your vector normalized in the "normal" fashion.
Upvotes: 1