gpt4 book ai didi

python - 无法在 scipy 中创建非空 csr.matrix()

转载 作者:太空宇宙 更新时间:2023-11-04 03:34:29 25 4
gpt4 key购买 nike

我需要稀疏矩阵来解决问题,根据 scipy 中 scr.matrix() 的描述 http://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csr_matrix.html#scipy.sparse.csr_matrix它非常适合我的问题。但是我什至无法初始化它。当我使用此文档中的空矩阵示例时 http://docs.scipy.org/doc/scipy-0.15.1/reference/generated/scipy.sparse.csr_matrix.html它工作正常,与文档中的完全一样

>>> import numpy as np
>>> from scipy.sparse import csr_matrix
>>> csr_matrix((3, 4), dtype=np.int8).toarray()
array([[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]], dtype=int8)

但是当我使用非空矩阵的例子或者尝试用我自己的数据填充它时

>>> row = np.array([0, 0, 1, 2, 2, 2])
>>> col = np.array([0, 2, 2, 0, 1, 2])
>>> data = np.array([1, 2, 3, 4, 5, 6])
>>> csr_matrix((data, (row, col)), shape=(3, 3)).toarray()

我总是收到这条消息

/Library/Python/2.7/site-packages/numpy-1.9.2-py2.7-macosx-10.10-
intel.egg/numpy/core/fromnumeric.py:2507: VisibleDeprecationWarning:
`rank` is deprecated; use the `ndim` attribute or function instead.
To find the rank of a matrix see `numpy.linalg.matrix_rank`.
VisibleDeprecationWarning)

这是什么意思?我完全卡住了。不好意思问这个问题,我是 scipy 的新手,需要帮助。

最佳答案

这只是一个警告,我希望创建您的矩阵。Scipy 正在调用一个旧的 numpy 函数。它已于 2014 年 4 月在 scipy 中修复。

Scipy 变化在: https://github.com/scipy/scipy/commit/fa1782e04fdab91f672ccf7a4ebfb887de50f01c

关于python - 无法在 scipy 中创建非空 csr.matrix(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29751985/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com