I have a defaultdict
which stores data co-occurence of every 2 words in a dataset. I have done this os as to get a sparse representation as not every pair is present in the dataset and hence to save some memory space.
Now are there some standard function which can convert this defaultdict
to a numpy
matrix, if possible to some sparse representation. I am aware of how to convert a dict to numpy array. But I am looking for a more efficient way of converting the defaultdict to matrix.
If it is not possible is there any standard function that convert the defaultdict to a CSV, so that I can load the csv using numpy.
Edit - I have found a workaround using pandas. I convert the defaultdict to DataFrame and then the DF to a numpy matrix. Is there any better method than this?
But sadly, this does not help with saving memory .