2

I am trying to create a random numpy array using np.random() but for some reason, instead of taking it as a function, google collab is taking it as a module, I checked the documentation, but I would prefer not to have a default_rng since as to my understanding, I will always get the same array with the same default_rng. I am very confused and help will be appreciated!

3
  • 3
    Maybe you're looking for np.random.random()? Commented Jul 1 at 16:15
  • Oh, .random() is from np.random. Silly me, I didn't read the first line where it said, "the module np.random". Commented Jul 1 at 16:17
  • No worries, glad to help! Commented Jul 1 at 16:17

1 Answer 1

1

NumPy doesn't have a function named `random` directly; instead, it has a module called `random`, and within that module, there's a function also named `random`.

If you're using VSCode and you `Cmd+Click` on `random` after writing

import random from numpy

it will take you to the source code. There, you can find all available functions and notes left by the developers for your reference.

You can perform the desired operation as shown below:

import numpy as np

np.random.rand(3, 4)

source code screenshot

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.