1

I have the following array:

myarray

array([4805, 5019, 5066, 5033, 5089, 5068, 5103, 5111, 5098, 5112, 5036,
   5010])

I am trying to normalize the data using sklearn function

sklearn.preprocessing.normalize(myarray)

and I get the following error message

/...python3.4/site-packages/sklearn/preprocessing/data.py in normalize(X, norm, axis, copy)

551             norms[norms == 0.0] = 1.0
552         elif norm == 'l2':
--->553         norms = row_norms(X)
554             norms[norms == 0.0] = 1.0
555         X /= norms[:, np.newaxis]

/.../python3.4/site-packages/sklearn/utils/extmath.py in row_norms(X, squared)
 63         norms = csr_row_norms(X)
 64     else:
---> 65         norms = np.einsum('ij,ij->i', X, X)
 66 
 67     if not squared:

ValueError: einstein sum subscripts string contains too many subscripts for operand 0

I converted the array to pandas.Series but I still get the same error message.

Any advice is much appreciated.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
georgeaueb
  • 41
  • 1
  • 5

1 Answers1

0

I ran into the same issue. I don't have a lot of experience in that area, but I think it is because normalize requires a matrix. If you are trying to normalize a list, have a look at Normalizing a list of numbers in Python.

Community
  • 1
  • 1
gduverger
  • 158
  • 1
  • 10