簡體   English   中英

Jupyter notebook 用 numpy 導入 other.py 文件不起作用

[英]Jupyter notebook import other .py file with numpy doesn't work

我正在使用 Jupyter notebook 導入另一個包含我的函數的.py 文件。 外部function需要numpy模塊。 但是當我運行時,它說“名稱'np'未定義”。

我嘗試從 my.py 文件或 Jupyter 導入 numpy,但它不起作用。 我不知道是什么導致了這里的問題。 即使我在 .py 文件中評論了 np 導入行並刪除了我使用 np 的行,錯誤仍然顯示。

在我的 Jupyter 筆記本中:

import test
import numpy as np
a = np.array([8,3])
m = test.test(a)

在 test.py 中:

import numpy as np
def test(x):
    m = np.mean(x)
    return m

當您在 jupyter notebook 上對加載的腳本進行更改時,您應該重新啟動 kernel,修復該問題的方法,即使在打印的日志中也會顯示您瘋狂的修改,但仍然是錯誤,我認為 jupyter 社區需要做出此錯誤的更新

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM