Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I translate this 'sparse' Matlab bsxfun call to R?
    primarykey
    data
    text
    <pre><code>&gt;&gt; A = sparse([1,2,3,4,5]) A = (1,1) 1 (1,2) 2 (1,3) 3 (1,4) 4 (1,5) 5 &gt;&gt; B = sparse([1;2;3;4;5]) B = (1,1) 1 (2,1) 2 (3,1) 3 (4,1) 4 (5,1) 5 &gt;&gt; bsxfun(@times, A, B) ans = (1,1) 1 (2,1) 2 (3,1) 3 (4,1) 4 (5,1) 5 (1,2) 2 (2,2) 4 (3,2) 6 (4,2) 8 (5,2) 10 (1,3) 3 (2,3) 6 (3,3) 9 (4,3) 12 (5,3) 15 (1,4) 4 (2,4) 8 (3,4) 12 (4,4) 16 (5,4) 20 (1,5) 5 (2,5) 10 (3,5) 15 (4,5) 20 (5,5) 25 </code></pre> <p>Which looks like this in non-sparse form:</p> <pre><code>&gt;&gt; full(ans) ans = 1 2 3 4 5 2 4 6 8 10 3 6 9 12 15 4 8 12 16 20 5 10 15 20 25 &gt;&gt; </code></pre> <p>EDIT:</p> <p>I would like to do a matrix multiplication of these sparse vectors, and return a sparse array:</p> <pre><code>&gt; class(NRowSums) [1] "dsparseVector" attr(,"package") [1] "Matrix" &gt; class(NColSums) [1] "dsparseVector" attr(,"package") [1] "Matrix" &gt; </code></pre> <p>NRowSums * NColSums (I think; or if that returns a scalar, then flip them) w/o using a non-sparse variable to temporarily store data.</p> <p>EDIT2:</p> <p>I currently have this:</p> <pre><code>NSums = tcrossprod(as(NRowSums, "sparseMatrix"), as(NColSums, "sparseMatrix")) </code></pre> <p>This seems a bit awkward for what I'm trying to do, especially the type castings. It's also extremely inneficient, because it computes all elements where either a NRowSum or NColSum exist, and not only the intersection of these two. That is, there are about 100x more entries in this NSums than in the original sparse matrix.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload