Valueerror: Urls Are Not Writeable (Np. Savetext)

I am doing text based clustering of various news articles using k-means clustering. I have cleaned the data of any stopwords, punctuations, stemmed etc. The clustering part is successful. The problem I am facing is in the part where I want to write the matrix as a text file.

vectorizer = TfidfVectorizer(stop)
X = vectorizer.fit_transform(train_clean_sentences)   
np.savetxt('E://csr.txt', X, delimiter=" ")

train_clean_sentences is a list of sentences I have pre-processed and cleaned, while X is a scipy.sparse.csr.csr_matrix

This code returns an error saying:

np.savetxt('E://csr.txt', X, delimiter=" ") Traceback (most recent call last):

File "", line 2, in np.savetxt('E://csr.txt', X, delimiter=" ")

File "C:\Anaconda3\lib\site-packages\numpy\lib\npyio.py", line 1308, in savetxt fh = np.lib._datasource.open(fname, 'wt', encoding=encoding)

File "C:\Anaconda3\lib\site-packages\numpy\lib_datasource.py", line 260, in open return ds.open(path, mode, encoding=encoding, newline=newline)

File "C:\Anaconda3\lib\site-packages\numpy\lib_datasource.py", line 605, in open raise ValueError("URLs are not writeable")

ValueError: URLs are not writeable

I have made it sure that the text to be converted does not contain any URLs as the punctuation has been removed.

The output text file should be something like this:

where each row will show the cluster distance of that centroid from other centroids in the cluster.

10
Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article