- The input is a 1M x 100K random
**sparse matrix**with density 0.001, containing 100M non-zero values: from scipy.**sparse**import random**matrix**= random(1000000, 100000, density=0.001, format="csr")**matrix**<1000000x100000**sparse matrix**of type '<type 'numpy.float64'>' with 100000000 stored elements in Compressed**Sparse**Row format> io.mmwrite / io.mmread **Sparse**data structures. ¶. pandas provides data structures for efficiently storing**sparse**data. These are not necessarily**sparse**in the typical “mostly 0”. Rather, you can view these objects as being “compressed” where any data matching a specific value ( NaN / missing value, though any value can be chosen, including 0) is omitted.**save_npz**¶.**save_npz**.**Save**a**sparse****matrix**to disk in numpy’s .npz format. Note: This is not binary compatible with scipy’s**save_npz**() . This binary format is not currently stable. Will**save**a file that can only be opend with this package’s load_npz (). filename ( string or file) – Either the file name (string) or an open file (file ...- Algorithm: Firstly, create an empty list (
**sparse****matrix**list). Then find the non-zero elements in the**matrix**by iterating the whole**matrix**. After that, if you find a non-zero element, create a temporary empty list and append details of the non-zero element in it (row, column and element). Append temporary list to**sparse****matrix**created.