Tom
Tom

Reputation: 461

Python Scikit Learn: 'argument 1 must be a unicode character, not a list

I am using the following array of tuples which I am storing as a temporary variable new_make_moons to test what happens when I change the make_moons dataset. Can someone tell me why I am getting the error? I have set the first argument as str('u') because that's what I found in another solution.

new_make_moons = (array([[  1.99794539e+00,   4.35929780e-01],
       [  5.95216657e-01,  -4.14412623e-01],
       [  1.46253829e+00,  -3.86599306e-01],
       [  1.61911895e-01,  -4.55349012e-02],
       [  7.77479066e-01,  -4.74927912e-01],
       [  1.96729486e+00,   2.46345416e-01],
       [  2.84527587e-01,   9.58667853e-01],
       [ -4.04783343e-01,   9.14412623e-01],
       [  1.98586378e-01,  -9.81105305e-02],
       [  9.97945393e-01,   6.40702200e-02],
       [ -7.18349350e-01,   6.95682551e-01],
       [  1.28452759e+00,  -4.58667853e-01],
       [  2.81650650e-01,  -1.95682551e-01],
       [  3.45365054e-01,   9.38468422e-01],
       [ -9.81559157e-01,   1.91158629e-01],
       [ -2.22520934e-01,   9.74927912e-01],
       [  1.67230089e+00,  -2.40277997e-01],
       [  1.59599895e-01,   9.87181783e-01],
       [  9.03976974e-01,  -4.95379113e-01]]), array(str("u"), [1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0,
       0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1,
       1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1,
       1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0,
       1, 1, 0, 0, 0, 1, 0, 1]))

Upvotes: 2

Views: 16943

Answers (2)

Abhay KanWasi
Abhay KanWasi

Reputation: 81

If you are working with matrix and getting this error then you can try these things:

  1. Check your proper indentations.
  2. Re write your code with proper indentation.

Upvotes: 0

Eduard Ilyasov
Eduard Ilyasov

Reputation: 3308

If you want to store in numpy ndarray elements with type different from float, you should specify dtype parameter in np.array():

arr = (np.array([[1,2],
                 [3,4],
                 [5,6]]),
       np.array([(str('u'), [1,2,3])], dtype=[('x', 'a1'), ('y', list)]))

After that in second np.array of your tuple you can store tuples of two elements (first - 1-character string , second - list)

Upvotes: 2

Related Questions