newWithPython
newWithPython

Reputation: 883

How to show the full scikit's sparse matrix

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?.

Upvotes: 0

Views: 1379

Answers (2)

pv.
pv.

Reputation: 35145

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.

Upvotes: 1

JAB
JAB

Reputation: 12801

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

Upvotes: 1

Related Questions