稀疏vs法线阵列Matlab [英] Sparse vs Normal Array Matlab

查看:68
本文介绍了稀疏vs法线阵列Matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Matlab中,如果仍然需要进行大量计算,并且稀疏数组要比普通数组好一点,并且该数组中约有25%是非零的,那在什么时候呢?

In Matlab, at what point is having a sparse array better than a normal array if I still have a lot of calculations to do on it, and about 25% of the array are non-zeros?

推荐答案

我个人很少会因为只有25%非零的数组而为稀疏而烦恼.如果您不相信我,请自己尝试.

Personally, I'd rarely bother with sparse for an array that is only 25% non-zeros. If you don't believe me, try it yourself.

A = sprand(2000,2000,0.25);
tic,B = A*A;toc
Elapsed time is 1.771668 seconds.

Af = full(A);
tic,B = Af*Af;toc
Elapsed time is 0.499045 seconds.

作为稀疏矩阵与此有关的额外工作花费太多,不值得打扰.现在,使用真正稀疏的矩阵进行尝试.

The extra work involved with this as a sparse matrix costs too much to be worth the bother. Now try it with a really sparse matrix.

A = sprand(2000,2000,0.005);
Af = full(A);

tic,B = A*A;toc
Elapsed time is 0.037763 seconds.

tic,B = Af*Af;toc
Elapsed time is 0.446680 seconds.

当然,您自己的问题会有所不同,但不会有太大的不同.对于使用真正稀疏矩阵的人来说,稀疏矩阵是一个真正的福音,但是在大多数情况下,只有25%的非零值不足以带来任何收益.

Of course, your own problem will be different, but it will not be that different. Sparse matrices are a true boon for the person who uses truly sparse matrices, but 25% non-zeros is simply not "sparse" enough for any gain in most cases.

这篇关于稀疏vs法线阵列Matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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