Borrar filtros
Borrar filtros

Avoid multiplying with 1 in element wise multiplication for large matrices

4 visualizaciones (últimos 30 días)
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.

Respuestas (2)

Walter Roberson
Walter Roberson el 14 de Mzo. de 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 el 14 de Mzo. de 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.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by