我使用的Spyder和寫了下面的類沒有定義:爲什麼我會得到NameError:名字「數組」
class Ray:
def __init__(self, r, p, k):
if r.shape == (3,):
self.r = r
if p.shape == (3,):
self.p = p
if k.shape == (3,):
self.k = k
r = array(range(3))
p = array(range(3))
k = array(range(3))
它存儲在/ home /用戶/工作區/ Spyder的/項目控制檯的工作目錄就是那個。在控制檯中,我可以運行一個數組(範圍(3)),並返回值爲0,1,2的數組。做
import ray
時不過,我得到以下錯誤
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "ray.py", line 8, in <module>
class Ray:
File "ray.py", line 20, in ray
r = array(range(3));
NameError: name 'array' is not defined
編輯:
默認Spyder的有以下行爲,實在不明白爲什麼陣列()的工作原理是默認我認爲這只是numpy的一部分。
import numpy as np # NumPy (multidimensional arrays, linear algebra, ...)
import scipy as sp # SciPy (signal and image processing library)
import matplotlib as mpl # Matplotlib (2D/3D plotting library)
import matplotlib.pyplot as plt # Matplotlib's pyplot: MATLAB-like syntax
from mayavi import mlab # 3D plotting functions
from pylab import * # Matplotlib's pylab interface
ion() # Turned on Matplotlib's interactive mode
Within Spyder, this intepreter also provides:
* special commands (e.g. %ls, %pwd, %clear)
* system commands, i.e. all commands starting with '!' are subprocessed
(e.g. !dir on Windows or !ls on Linux, and so on)
你錯過了一些進口。 – wRAR 2013-03-23 10:58:45
附註:爲了遵循PEP 8,我用大寫字母開始了你的類名,我在'__init __()'參數之間加了空格。我也刪除了不必要的結尾「;」並且讓「Ray」成爲一種新式的課程。 (好吧,那是在你再次編輯它之前,你可能想考慮把我的改進放回去) – EOL 2013-03-23 11:09:40
'from pylab import *'的註釋是錯誤的:它在內部從'numpy import *'中執行。 – wRAR 2013-03-23 11:59:22