在Matlab中向稀疏向量添加稀疏向量 [英] Adding a sparse vector to a dense vector in Matlab
问题描述
假设我有一个高维向量v,它很密集,而另一个高维向量x是稀疏的,我想做一个看起来像
Suppose I have a high dimensional vector v which is dense and another high dimensional vector x which is sparse and I want to do an operation which looks like
v = v + x
v = v + x
理想情况下,由于只需要更新v中的几个条目,此操作应该很快,但是即使我声明x为稀疏状态,它仍然要花费大量时间.我已经尝试过v处于完全状态以及v处于稀疏状态,并且两者都相当慢.
Ideally since one needs to update only a few entries in v this operation should be fast but it is still taking a good amount of time even when I have declared x to be sparse. I have tried with v being in full as well as v being in sparse form and both are fairly slow.
我还试图通过调用find从稀疏向量x中提取索引,然后在for循环中更新原始向量.这比上面的操作要快,但是有一种方法可以用更少的代码来实现相同的目的.
I have also tried to extract the indices from the sparse vector x by calling a find and then updating the original vector in a for loop. This is faster than the above operations, but is there a way to achieve the same with much less code.
谢谢