Can anyone clarify the following behavior. I ran into it in a bigger piece of code, but I created a minimal example
File untitled0.py
consists of the following code:
import numpy as np
class A:
def f(self,x):
return np.diag(x)
File untitled1.py
consists of the following code:
import untitled0 as u0
import numpy as np
a=u0.A()
print a.f([1])
The output is simple and [[1]] is printed on the screen. Now suppose you have created a
(an instance of A) with a lot of computational effort and continue writing your script and don't want to recompute all the time. What I then normally do is simply commenting out the creation line (since the object a is already exists in you python shell anyway), i.e.:
import untitled0 as u0
import numpy as np
#a=u0.A()
print a.f([1])
However, when I run this script it leads to the error:
UMD has deleted: untitled0
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\WinPython-64bit-2.7.5.1\python-2.7.5.amd64\lib\site-packages\spyderlib\widgets\externalshell \sitecustomize.py", line 523, in runfile
execfile(filename, namespace)
File "M:\....\untitled1.py", line 12, in <module>
print a.f([1])
File "untitled0.py", line 12, in f
return np.diag(x)
AttributeError: 'NoneType' object has no attribute 'diag'
For some reason np
is not defined inside untitled0.py
. Can anyone explain what happened?
$pip freeze
to see ifnumpy
is installed in your python environment – Greg Aug 26 '13 at 8:20