0
0
SciPydata~5 mins

Sparse matrix file I/O in SciPy - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a sparse matrix?
A sparse matrix is a matrix mostly filled with zeros. It saves memory by only storing the non-zero values and their positions.
Click to reveal answer
beginner
Which SciPy module is commonly used for sparse matrix file input/output?
The scipy.sparse module along with scipy.io is used to save and load sparse matrices efficiently.
Click to reveal answer
intermediate
How do you save a sparse matrix to a file using SciPy?
Use scipy.io.savemat to save a sparse matrix in MATLAB format or scipy.sparse.save_npz to save in compressed NumPy format.
Click to reveal answer
intermediate
How do you load a sparse matrix saved in NPZ format?
Use scipy.sparse.load_npz(filename) to load the sparse matrix back into memory.
Click to reveal answer
beginner
Why is it better to use sparse matrix file formats instead of saving as dense arrays?
Saving sparse matrices in special formats keeps file size small and loading fast because it only stores non-zero values, unlike dense arrays which store all values including zeros.
Click to reveal answer
Which function saves a sparse matrix in compressed NPZ format?
Ascipy.sparse.save_npz
Bscipy.io.savemat
Cnumpy.save
Dscipy.sparse.load_npz
What does a sparse matrix mainly store to save space?
AOnly zero values
BAll values including zeros
COnly non-zero values and their positions
DOnly the diagonal values
Which function loads a sparse matrix saved in NPZ format?
Ascipy.io.loadmat
Bscipy.sparse.load_npz
Cnumpy.load
Dscipy.sparse.save_npz
What file format does scipy.io.savemat save data in?
AMATLAB .mat format
BCSV format
CJSON format
DNPZ format
Why should you use sparse matrix file I/O methods instead of saving as dense arrays?
ABecause dense arrays are faster to save
BDense arrays use less memory
CSparse matrix file I/O is slower but more accurate
DTo save disk space and load data faster
Explain how to save and load a sparse matrix using SciPy.
Think about the functions for saving and loading NPZ files.
You got /4 concepts.
    Why is it important to use sparse matrix file I/O methods instead of saving as dense arrays?
    Consider the difference in storage between sparse and dense matrices.
    You got /4 concepts.