sparse#

pybear.new_numpy.random.sparse(minimum, maximum, shape, sparsity, dtype=<class 'numpy.float64'>)#

Return random values from a “discrete uniform” (integer) or “uniform” (float) distribution of the specified dtype in the “half-open” interval [minimum, maximum) (includes low, but excludes the maximum), with desired sparsity.

Samples are uniformly distributed over the interval. In other words, any value within the given interval is equally likely to be drawn.

This function is a simplified Sparse implementation.

Parameters:
minimumnumbers.Real

Lowest (signed) value to be drawn from the distribution.

maximumnumbers.Real

Upper boundary of the output interval. All values generated will be less than this number.

shapeint | Sequence[int]

Dimensions of the returned array.

sparsitynumbers.Real, default = 0

Desired percentage of zeros in the returned array.

dtypeobject, default = float

Desired dtype of the result.

Returns:
sparse_arraynumpy.ndarray[numbers.Real]

Array of dimension shape with random values from the appropriate distribution and with the specified sparsity.

See also

numpy.random.randint
numpy.random.uniform
pybear.random.Sparse

Examples

>>> from pybear.new_numpy.random import sparse as pb_sparse
>>> sparse_array = pb_sparse(11, 20, (4,4), 70, dtype=np.int8)
>>> print(sparse_array)
[12  0  0 13]
[0 16  0  0]
[0  0  0 17]
[0  0  0 16]]