In brief
This blog post proclaims and briefly describes a Python package that implements the function random_sparse_matrix, which can be used to generate random sparse matrices.
The sparse matrices have named rows and columns — see the package “SSparseMatrix”, [AAp1].
Functions from the package “RandomDataGenerators”, [AAp2], are used to obtain row- and column names and entry values. (See the previous post of this blog.)
Installation
To install from GitHub use the shell command:
python -m pip install git+https://github.com/antononcube/Python-packages.git#egg=RandomSparseMatrix\&subdirectory=RandomSparseMatrix
To install from PyPI:
python -m pip install RandomSparseMatrix
Examples
Here is random sparse matrix (SSparseMatrix object) with 6 rows and 4 columns:
import random
from RandomSparseMatrix import *
random.seed(87)
rmat = random_sparse_matrix(6, 4,
column_names_generator=random_pet_name,
row_names_generator=random_word,
min_number_of_values=6,
max_number_of_values=None)
rmat.print_matrix(n_digits=20)
# ============================================================================================
# | Cleo Diamond Max Tessa
# --------------------------------------------------------------------------------------------
# cuticular | . . . 12.886794438387263
# elysian | . . . 13.891135469455826
# spot-check | . 11.465064963144142 . .
# cetacean | . 9.626463367706222 . .
# idem | 5.474873249244756 . . .
# lot | . . 10.818678723268317 .
# ============================================================================================
References
[AAp1] Anton Antonov, SSparseMatrix Python package, (2021), PyPI.
[AAp2] Anton Antonov, RandomDataGenerators Python package, (2021), PyPI.
[AAp3] Anton Antonov, SparseMatrixRecommender Python package, (2021), PyPI.