Filter löschen
Filter löschen

Avoid multiplying with 1 in element wise multiplication for large matrices

4 Ansichten (letzte 30 Tage)
Erdem Uguz
Erdem Uguz am 14 Mär. 2016
Beantwortet: Guillaume am 14 Mär. 2016
Hello, I have really large matrices (100000x100000) I want to multiply them element wise. One of them has %90 ones and I would like to avoid multiplying with those. Is there a quick way of doing that? That will save a lot of cpu time.

Antworten (2)

Walter Roberson
Walter Roberson am 14 Mär. 2016
Constructing the logical mask and extracting the subset and storing it back, would probably take more time than just having it proceed. However, if the positions of the non-1's is not changing, perhaps it would be worth constructing a sparse logical vector.

Guillaume
Guillaume am 14 Mär. 2016
I'm really not convinced you'll have any gain in speed. Identifying the ones and filtering both input matrix is probably going to take just as long as the multiplication.
%A: a matrix
%B: another matrix the same size as A, with lots of 1.
%C = A .* B
C = A; %default resut is multiplication by 1
isnotone = B ~= 1; %identify the 1s in B
C(isnotone) = A(isnotone) .* B(isnotone); %multiply only those elements for which B is not one.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by