0

The method available in python scipy sps.rand() generates sparse matrix of random values in the range (0,1). How can we generate discrete random values greater than 1 like 2, 3,etc. ? Any method in scipy, numpy ?

1

1 Answer 1

1

sparse.rand calls sparse.random. random adds a optional data_rvs.

I haven't used data_rvs. It can probably emulate the dense randint, but definition is more complicated.

Another option is to generate the random floats and then convert them with a bit of math to the desired integers. You have to be a little careful since some operations will produce a Sparse Efficiency warning. You want operations that will change the nonzero values without touching the zeros.

(I suspect the data_rvs parameter was added in newer Scipy version, but I don't see an indication in the docs).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.