0

Basicaly i am trying to do the same thing as in this question but in python.

What i tried so far:

I read the file and save it in a dataframe. Then i use this code A = np.array(df) to create a numpy array. My problem is that when i try to convert it to a sparse using the code s = sparse.csr_matrix(A) i get this error TypeError: Cannot cast array data from dtype('O') to dtype('bool') according to the rule 'safe'

caspar
  • 13
  • 6
  • Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation. [Minimal, complete, verifiable example](http://stackoverflow.com/help/mcve) applies here. We cannot effectively help you until you post your code and accurately describe the problem. – Prune Dec 03 '15 at 01:40
  • I posted the code i am using except the code i use to load the file that is common and has nothing to do with the problem. – caspar Dec 03 '15 at 01:44
  • The problem in your `df`, it is likely to contain strings, which drives to dtype='O'. Also, hard luck you were able to save ratings in pandas, because this is matrix of huge size and pandas.DataFrame is dense – Alleo Dec 03 '15 at 02:08
  • Thats why i want to use a sparse matrix. And yes it contains strings. Do you suggest an other approach? – caspar Dec 03 '15 at 02:11
  • 2
    Show us the `A` shape, and a sample of the values. From the error we already know `dtype=object`. Have you tried the panada version of sparse? Also tell us what you want to do with this sparse matrix. – hpaulj Dec 03 '15 at 03:27

0 Answers0