下記のように、test.pyからモジュールfuncの中の関数testfuncを呼び出して
使おうとしているのですが、test.pyで呼び出したライブラリnumpyが使えず、
次のエラーが出ます。
関数の中でライブラリnumpyを使うにはどのようにしたら
NameError Traceback (most recent call last)
test.py in <module>()
3
4 x = np.array([1,3,5,8])
----> 5 s = testfunc(x)
func.py in testfunc(x)
1 def testfunc(x):
----> 2 s = np.sum(x)
NameError: global name 'np' is not defined
func.py
python
1def testfunc(x): 2 s = np.sum(x)
test.py
python
1import numpy as np 2from func import testfunc 3 4x = np.array([1,3,5,8]) 5s = testfunc(x)
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。