pythonarrayslistnumpyrandom

np.random() is getting treated as module


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!


Solution

  • 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