bsparse.random#
- random(bshape, density=0.1, dtype=None, format='bcoo')#
Create a sparse random matrix of specified shape and density.
- Parameters:
- bshapetuple[int, int]
The bshape of the matrix.
- densityfloat, optional
The density of the matrix, by default 0.1.
- dtypenp.dtype, optional
The data type of the matrix elements, by default None.
- formatstr, optional
The sparse format of the matrix, by default “coo”.
- Returns:
- BSparse
A sparse random matrix of specified shape and density.
Examples
>>> bcoo = random((3,3)) >>> bcoo BCOO(bshape=(3, 3), bnnz=0 | shape=(3, 3), nnz=0) >>> bcoo = random((3,3), density=0.9) >>> bcoo BCOO(bshape=(3, 3), bnnz=8 | shape=(3, 3), nnz=8) >>> bcoo.toarray() array([[0. , 0.15029409, 0.52752179], [0.146725 , 0.44512433, 0.48044659], [0.6987136 , 0.78170356, 0.09361786]])