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

查看:139
本文介绍了有没有一种有效的方法来连接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()

推荐答案

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

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

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

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