Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SciPy module names and functions fail to be defined

I just installed ANACONDA and have set up my virtual environment and profile. When I enter a command like

from pandas import * 

or

from numpy import random

the system pauses for a second before moving on to the next line, as expected. However, when I try to enter a command like

x = randn(100,100) 

I get a message saying

name 'randn' is not defined

Also, when I run

imp.find_module("pandas")

I get

(None, 'C:\\Anaconda\\lib\\site-packages\\numpy', ('', '', 5))

Any ideas?

like image 407
Connor O'Doherty Avatar asked Feb 14 '23 09:02

Connor O'Doherty


1 Answers

Your message title refers to scipy, but you didn't import anything from it, so I'm not sure why that's relevant. You did two imports:

from pandas import *

which I wouldn't actually recommend; I know it's done in some tutorials, but I prefer

import pandas as pd

to keep the namespace clean. In any case, randn isn't defined in the pandas namespace. Then you run

from numpy import random

which only adds one new name to the namespace: random. After you've done this, you can access randn via random.randn:

>>> from numpy import random
>>> random.randn(3)
array([-1.19504793, -0.54873061, -1.46225504])

If you really want to use simply randn, you could do

from numpy.random import randn
like image 104
DSM Avatar answered Feb 16 '23 04:02

DSM