2

Currently, I am writing this:

    x, y = np.array([random.randint(0, 9), random.randint(0, 9), random.randint(0, 9)]), \
           np.array([random.randint(0, 9), random.randint(0, 9), random.randint(0, 9)])

Is there a built-in NumPy function to allow me to do this a bit better?

I said N-dimensional array not because I want to generate a random-sized vector with random values, but rather so others can apply it for their own vectors.

1 Answer 1

4

You can use:

import numpy as np
np.random.randint(0, 9, shape)

For example, with shape=(2, 3):

array([[3, 2, 0], [1, 0, 1]])

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.