scipy 相当于 MATLAB spy [英] scipy equivalent for MATLAB spy

查看:38
本文介绍了scipy 相当于 MATLAB spy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在将 isomap 算法的代码从 MATLAB 移植到 Python.我正在尝试使用 spy 函数可视化稀疏模式.

I have been porting code for an isomap algorithm from MATLAB to Python. I am trying to visualize the sparsity pattern using the spy function.

MATLAB 命令:

spy(sparse(A));
drawnow;

Python 命令:

matplotlib.pyplot.spy(scipy.sparse.csr_matrix(A))
plt.show()

我无法使用上述命令在 Python 中重现 MATLAB 结果.在非稀疏格式中使用仅包含 A 的命令会得到与 MATLAB 非常相似的结果.但这需要很长时间(A 是 2000 年到 2000 年).scipy 稀疏函数的 MATLAB 等效项是什么?

I am not able to reproduce the MATLAB result in Python using the above command. Using the command with only A in non-sparse format gives quite similar result to MATLAB. But it's taking quite long (A being 2000-by-2000). What would be the MATLAB equivalent of a sparse function for scipy?

推荐答案

可能是你的 matplotlib 版本出了问题,至于我 scipy.sparse>matplotlib.pylab 可以很好地协同工作.

Maybe it's your version of matplotlib that makes trouble, as for me scipy.sparse and matplotlib.pylab work well together.

请参阅下面的示例代码,生成附加的间谍"图.

See sample code below that produces the 'spy' plot attached.

import matplotlib.pylab as plt
import scipy.sparse as sps
A = sps.rand(10000,10000, density=0.00001)
M = sps.csr_matrix(A)
plt.spy(M)
plt.show()

# Returns here '1.3.0'
matplotlib.__version__

这给出了这个图:

这篇关于scipy 相当于 MATLAB spy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆