Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 765
Outcast Avatar asked Aug 09 '19 16:08

Outcast


2 Answers

You may redefine your numpy array specifying the dtypeexplicitly

features = np.array(features, dtype=float)
like image 103
rafaelc Avatar answered Oct 17 '22 19:10

rafaelc


Do this:

csr_matrix(features.astype(np.float))

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

like image 39
Kyle Pena Avatar answered Oct 17 '22 20:10

Kyle Pena