Random Python module inaccessible to random Numpy module

When I call the random.sample(arr,length) error returns random_sample() takes at most 1 positional argument (2 given). After some Googling, I found out that I call the Numpy random fetch function when I want to call the random module fetch function. I tried to import numpy under a different name, which does not fix the problem. I need Numpy for the rest of the program.

Any thoughts? Thanks

+5
source share
4 answers

It looks like you have something like

import random
from numpy import *

and randomgets clobbered from numpy import. If you want to save import *, then you will need to rename random:

import random as rnd    # or whatever name you like
from numpy import *

, , , , numpy , :

import random
import numpy as np      # or leave as numpy, or whatever name you like
+14

. , from numpy import *.

+5

Be sure to save the import:

>>> import numpy.random
>>> import random         # python random
+5
source

Using:

import numpy as np
import pandas as pd
import random as rd

Instead:

import numpy as np import pandas as pd import random

0
source

All Articles