PyCharm Community 3.1.1 and Numpy, “'matrix' is not callable”, but the code works

China☆狼群 提交于 2020-01-15 05:42:27

问题


I have the following code:

import numpy as np

if __name__ == "__main__":
    m = np.matrix([[1, 0, 0],
                   [0, 1, 0],
                   [0, 0, 1]])
    print(m)

The code runs as expected, but PyCharm seems to think that 'matrix' is not callable. See screenshot.

Since the code runs, clearly 'matrix' is callable. So what's PyCharm complaining about? Am I in the wrong here or is PyCharm? How do I suppress this error?


回答1:


A simple workaround, at least until the bug is fixed, is to use np.mat(...) instead of np.matrix(...).

However, note that np.mat will avoid making copies if the input is already a matrix and so you can't use it to do things like make defensive copies.



来源:https://stackoverflow.com/questions/22635315/pycharm-community-3-1-1-and-numpy-matrix-is-not-callable-but-the-code-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!