PyCharm Community 3.1.1 and Numpy, “'matrix

2019-07-15 17:31发布

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.

enter image description here

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条回答
冷血范
2楼-- · 2019-07-15 18:05

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.

查看更多
登录 后发表回答