Outcast
Outcast

Reputation: 5117

Covert to sparse matrix - TypeError: no supported conversion for types: (dtype('0'),)

I am trying to do this:

  features = csr_matrix(features)

where features is a <class 'numpy.ndarray'> and looks like that:

[[51 1]
 [49 2]
 [47 2]
 ...
 [2 6]
 [20 2]
 [16 1]]

but I get the following error:

TypeError: no supported conversion for types: (dtype('O'),)

What is this error about and how can I fix it?

Upvotes: 8

Views: 8266

Answers (2)

rafaelc
rafaelc

Reputation: 59274

You may redefine your numpy array specifying the dtypeexplicitly

features = np.array(features, dtype=float)

Upvotes: 9

Kyle Pena
Kyle Pena

Reputation: 537

Do this:

csr_matrix(features.astype(np.float))

If this has an error, then you have things that aren't numbers in your features.

Upvotes: 2

Related Questions