cupyx.scipy.sparse.random#

cupyx.scipy.sparse.random(m, n, density=0.01, format='coo', dtype=None, random_state=None, data_rvs=None)[source]#

Generates a random sparse matrix.

This function generates a random sparse matrix. First it selects non-zero elements with given density density from (m, n) elements. So the number of non-zero elements k is k = m * n * density. Value of each element is selected with data_rvs function.

Parameters:
  • m (int) – Number of rows.

  • n (int) – Number of cols.

  • density (float) – Ratio of non-zero entries.

  • format (str) – Matrix format.

  • dtype (dtype) – Type of the returned matrix values.

  • random_state (cupy.random.RandomState or int) – State of random number generator. If an integer is given, the method makes a new state for random number generator and uses it. If it is not given, the default state is used. This state is used to generate random indexes for nonzero entries.

  • data_rvs (callable) – A function to generate data for a random matrix. If it is not given, random_state.rand is used.

Returns:

Generated matrix.

Return type:

cupyx.scipy.sparse.spmatrix