1

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?

Incognito
  • 331
  • 1
  • 5
  • 14
  • Do you mean the L2 norm (Euclidean distance), calculated as the square root of the sum of the squared vector values? – Samuel Aug 06 '20 at 21:34
  • Does this answer your question? [How to normalize an array in NumPy?](https://stackoverflow.com/questions/21030391/how-to-normalize-an-array-in-numpy) – Samuel Aug 06 '20 at 21:39

2 Answers2

1

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.

Prune
  • 76,765
  • 14
  • 60
  • 81
0

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.

Samuel
  • 2,895
  • 4
  • 30
  • 45