python-inverse-of-a-matrix 导入失败
我认为 python-inverse-of-a-matrix 中的代码非常有趣,特别是因为我在涉及矩阵的计算中使用 numpy 已有好几年了。我很失望,因为 numpy 的 2 次导入失败了。以下是导入内容:
from numpy import matrix
from numpy import linalg
在 numpy 包中找不到矩阵和 linalg。显然,我错过了一些非常明显的东西(但不适合我:))。
我使用 Linux (kubuntu) 并将 numpy 包下载为 debian 包。是否还有其他用于“matrix”和“linalg”的软件包,如果有,它们是什么?
谢谢你的期待,
OldAl。
I thought that the code in the python-inverse-of-a-matrix was extremely interesting, particularly since I have used numpy for several years in computations that involve matrices. I was disappointed as the 2 imports from numpy failed. Here are the imports:
from numpy import matrix
from numpy import linalg
Neither matrix nor linalg were found in the numpy package. Clearly I miss something that is quite obvious (not for me, though :) ).
I use Linux (kubuntu) and downloaded the numpy package as a debian package. Are there other packages for "matrix" and for "linalg", if so, what are they?
Thank you in anticipation,
OldAl.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最有可能的是,您的本地目录中有一个 numpy.py 或 numpy.pyc 文件...并且 python 正在找到它并导入它,而不是您期望的 numpy 包。
在导入之前尝试此操作。
您可能会发现 numpy.__file__ 不是指向 numpy 包,而是指向您不打算导入的内容。
一般来说,最好使用与已知/流行包不同的名称来命名您自己的模块。
Most likely, you have a
numpy.py
ornumpy.pyc
file in your local directory... and python is finding it and importing it instead of the numpy package you expect.Try this before importing.
You'll probably find that
numpy.__file__
is pointing not to the numpy package, but to something you did not intend to import.In general, it's a good idea to name your own modules with different names from known/popular packages.
已解决
deb 包 numpy 根本没有 Matrix 和 linalg 子包。
在 ubuntu 或 kubuntu 中还需要导入 scipy。 Scipy 扩展了 numpy 的名称空间并添加了矩阵和 linalg 包。
老阿尔。
SOLVED
The deb package numpy simply does not have the matrix and linalg sub-packages.
In ubuntu or kubuntu one needs to import scipy as well. Scipy expands the name space of numpy and adds matrix and linalg packages.
OldAl.