필터 지우기
필터 지우기

Avoid multiplying with 1 in element wise multiplication for large matrices

조회 수: 4 (최근 30일)
Erdem Uguz
Erdem Uguz 2016년 3월 14일
답변: Guillaume 2016년 3월 14일
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.

답변 (2개)

Walter Roberson
Walter Roberson 2016년 3월 14일
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 2016년 3월 14일
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.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by