本文介绍了PyCharm社区3.1.1和Numpy,“'矩阵'不可调用",但代码有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

import numpy as np

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

代码按预期运行,但是PyCharm似乎认为'matrix'是不可调用的.查看屏幕截图.

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

由于代码运行,因此显然可以调用矩阵".那么PyCharm在抱怨什么呢?我在这里错了吗?还是PyCharm?如何抑制此错误?

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?

推荐答案

一个简单的解决方法,至少在错误修复之前,是使用np.mat(...)而不是np.matrix(...).

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

但是,请注意,如果输入已经是矩阵,则np.mat将避免进行复制,因此您不能使用它来进行防御性复制.

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.

这篇关于PyCharm社区3.1.1和Numpy,“'矩阵'不可调用",但代码有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 15:09