python - Jupyter notebook 使用 numpy 导入其他 .py 文件不起作用
问题描述
我正在使用 Jupyter notebook 导入另一个包含我的函数的 .py 文件。外部函数需要 numpy 模块。但是当我运行时,它说“名称'np'未定义”。
我试图从我的 .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
解决方案
推荐阅读
- for-loop - SIMULINK:对工作区中数组的每个元素重复子系统并重新组合信号
- javascript - 尝试使用第一个数组的子集“交叉”两个数组并在可能的情况下保持第二个数组的顺序
- sql - 通过使用 DECODE 函数,将日期更改为任何字符串?
- c++ - 从具有默认值的部分指定模板类继承时出现 SWIG 错误,前向声明没有默认值
- node.js - 制作我自己的 npm 包,不断收到 TypeScript 错误
- angular - 从数据源到查看@angular/elements 的目标数据绑定的一种方式
- php - 如何使用 CI 访问 tpl 文件下的徽标或图像?
- reactjs - React.memo 的性能比 React.PureComponent 差
- python - 如何使用纬度和经度在散景图形对象上绘制点?
- excel - 如何将一列导入新工作表?