scipy.sparse 矩阵中 csr_matrix 中的非零值

发布于 2024-08-27 10:33:49 字数 114 浏览 1 评论 0原文

scipy 库的 csr_matrix 有一个 nonzero() 方法,但是尝试将该函数用于 csr 矩阵会导致错误,根据手册应返回带有行和列数组的元组。关于这个问题有什么想法吗?

此致, 乌穆特

There is a nonzero() method for the csr_matrix of scipy library, however trying to use that function for csr matrices result in an error, according to the manual that should return a tuple with row and colum arrays. Any ideas on this problem?

Best regards,
Umut

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

被你宠の有点坏 2024-09-03 10:33:49

Umut,你能提供一个代码片段吗?以下内容对我有用:

import scipy.sparse as sparse
x = sparse.csr_matrix([[1,0,1],[0,1,0]])
x.nonzero()

并产生

(array([0, 0, 1], dtype=int32), array([0, 2, 1], dtype=int32))

这是 scipy 的最新开发版本(您可以通过打印 scipy.__version__ 进行检查)。

Umut, could you provide a code snippet? The following works for me:

import scipy.sparse as sparse
x = sparse.csr_matrix([[1,0,1],[0,1,0]])
x.nonzero()

and yields

(array([0, 0, 1], dtype=int32), array([0, 2, 1], dtype=int32))

This is for the latest development version of scipy (you can check by printing scipy.__version__).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文