Effacer les filtres
Effacer les filtres

Avoid multiplying with 1 in element wise multiplication for large matrices

4 vues (au cours des 30 derniers jours)
Erdem Uguz
Erdem Uguz le 14 Mar 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.

Réponses (2)

Walter Roberson
Walter Roberson le 14 Mar 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 le 14 Mar 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.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by