Python AttributeError: module object has no attribute

为什么我写了这个属性却报错

写了一个模块文件hellohello.py

import numpy as np
def xgate(qinput):
        xmat = np.matrix([[0, 1],
                    [1, 0]])
        return np.matmul(xgate,qinput)
    
    

在Jupyter Notebook上

import numpy as np
state1 = np.array([0.2,0.8])
state1 = state1[:,None]
import hellohello
hellohello.xgate(state1)

报错

clipboard.png

阅读 3k
2 个回答
✓ 已被采纳新手上路,请多包涵

是jupyter notebook默认路径的问题,改完环境变量就解决了

更改hellohello.py文件:

import numpy as np
def xgate(qinput):
    xmat = np.matrix([[0, 1],[1, 0]])
    return np.matmul(xmat,qinput)
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题