我試圖用numpy
方法調用searchsorted
,但我無法使其工作。searchsorted - 未定義全局名稱「x」
這是代碼:
class Object(QMainWindow):
def __init__(self):
QMainWindow.__init(self)
self.figure_canvas = FigureCanvas(Figure())
self.axes = self.figure_canvas.add_subplot(111)
x = np.arange(0.0, 5.0, 0.01)
y = np.sin(2*np.pi*x) + 0.5*np.random.randn(len(x))
self.axes.plot(x, y, "-", picker = 5)
self.axes.set_ylim(-2, 2)
def onselect(xmin, xmax):
indmin, indmax = np.searchsorted(x, (xmin, xmax)
,當我嘗試建立這個代碼,我得到一個錯誤,指出:
NameError: global name 'x' is not defined
問題是什麼?我定義了我想要使用的x,但它表示它不是。
希望你能幫助我。
存在丟失的')'。 –
變量x剛剛在__init__函數中聲明,但對onselect()不可見( –