1

Creating and array like

random_num = np.random.randint(10,20)
arr_rand = np.random.randint(random_num, size = (4,2))

works normally, but how do I make the minimum value a negative number? I get the two errors:

ValueError                                Traceback (most recent call last)
<ipython-input-207-7a3b85248cc6> in <module>
      1 random_num = np.random.randint(-10,20)
----> 2 arr_rand = np.random.randint(random_num, size = (4,2))

mtrand.pyx in numpy.random.mtrand.RandomState.randint()

_bounded_integers.pyx in numpy.random._bounded_integers._rand_int32()

ValueError: low >= high

Also, they should preferrably be floats. The only other way I know how to do it is with the usual randn that generates values between 0 and 1.

1
  • Your existing code doesn't do what you think it does, by the way. 10 and 20 aren't the bounds on your random array. You're generating a random upper bound, and then generating an array of numbers between 0 (inclusive) and that random upper bound (exclusive). Commented Nov 7, 2021 at 4:03

2 Answers 2

2

You don't need to call np.random.randint twice. This will work:

np.random.randint(-10,20,(4,2))
Sign up to request clarification or add additional context in comments.

Comments

1

I believe you are looking for np.random.uniform(-10,20). Here is the documentation.

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.