是否有连接 scipy.sparse 矩阵的有效方法? [英] Is there an efficient way of concatenating scipy.sparse matrices?

查看:26
本文介绍了是否有连接 scipy.sparse 矩阵的有效方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一些相当大的稀疏矩阵(从 5000x5000 到 20000x20000),需要找到一种以灵活方式连接矩阵的有效方法,以便从不同的部分构建一个随机矩阵.

I'm working with some rather large sparse matrices (from 5000x5000 to 20000x20000) and need to find an efficient way to concatenate matrices in a flexible way in order to construct a stochastic matrix from separate parts.

现在我正在使用以下方法连接四个矩阵,但效率极低.有没有更好的方法来做到这一点而不涉及转换为密集矩阵?

Right now I'm using the following way to concatenate four matrices, but it's horribly inefficient. Is there any better way to do this that doesn't involve converting to a dense matrix?

rmat[0:m1.shape[0],0:m1.shape[1]] = m1
rmat[m1.shape[0]:rmat.shape[0],m1.shape[1]:rmat.shape[1]] = m2
rmat[0:m1.shape[0],m1.shape[1]:rmat.shape[1]] = bridge
rmat[m1.shape[0]:rmat.shape[0],0:m1.shape[1]] = bridge.transpose()

推荐答案

稀疏库现在有 hstackvstack 分别用于水平和垂直连接矩阵.

The sparse library now has hstack and vstack for respectively concatenating matrices horizontally and vertically.

这篇关于是否有连接 scipy.sparse 矩阵的有效方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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