Error NameError: name ‘np’ is not defined

As @aydow says, “change from numpy import * to import numpy as np“:

import numpy as np
...

Or don’t write np:

from numpy import *
x = random.randint(low=10, high=30, size=6)
...

Because, from numpy import *, Import every function in numpy, so np is not a function of numpy, so have to Import numpy like import numpy as np, Or, Remove np part of np.random.randint(low=10, high=30, size=6), and make it like this: random.randint(low=10, high=30, size=6), it’s all since random is a function of numpy, basically that’s all, to explain

Leave a Comment

tech