0

I am vectorizing with tfidf:

X = tfidf_vect.fit_transform(df['string'].values)

I would like to se the whole matrix of the above code so I tried this:

print X.toarray()

And obtained this:

[[0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 ..., 
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 0 0]]

How can I write to some txt file or see the full matrix X?.

newWithPython
  • 853
  • 3
  • 9
  • 20
  • 1
    Do you want to see it with all the 0s, or would a list of non zero entries be better. What is the size (shape) of this array? – hpaulj Feb 08 '15 at 04:49
  • Both could be nice to see how it looks, thanks! – newWithPython Feb 08 '15 at 05:27
  • 1
    There is an equivalent of the MATLAB `spy` function which plots an image of the sparsity of a sparse matrix: http://stackoverflow.com/questions/18651869/scipy-equivalent-for-matlab-spy – hpaulj Feb 08 '15 at 08:11

2 Answers2

1

Here is how you can write it to a text file:

pd.DataFrame(X.toarray()).to_csv('bow.csv')

Keep in mind that it can have very high 'n', and might make for a very large .txt

JAB
  • 12,401
  • 6
  • 45
  • 50
1

For interactive use, you can change the number of items to show

numpy.set_printoptions(edgeitems=1e9)

For saving to text files, use numpy.savetxt(X.toarray()) or some other similar function.

pv.
  • 33,875
  • 8
  • 55
  • 49