필터 지우기
필터 지우기

Can't multiply sparse logical matrices?

조회 수: 3 (최근 30일)
Nachiketa Sahoo
Nachiketa Sahoo 2012년 6월 13일
편집: Thomas Richner 2017년 12월 12일
Is there a way to multiply sparse logical matrices? I guess I am looking for a space efficient way to multiply matrices that contain only 0/1?
>> m = magic(5)
m =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
>> a = m>5
a =
1 1 0 1 1
1 0 1 1 1
0 1 1 1 1
1 1 1 1 0
1 1 1 0 1
>> b = m>10
b =
1 1 0 0 1
1 0 0 1 1
0 0 1 1 1
0 1 1 1 0
1 1 1 0 0
>> a+b
ans =
2 2 0 1 2
2 0 1 2 2
0 1 2 2 2
1 2 2 2 0
2 2 2 0 1
>> a*b
Error using *
Both logical inputs must be scalar.
To compute elementwise TIMES, use TIMES (.*) instead.

답변 (2개)

the cyclist
the cyclist 2012년 6월 13일
The short answer is "no". However ...
I asked about multiplication of logical matrices a while back. There were some answers that might be helpful to you in the thread:

Thomas Richner
Thomas Richner 2017년 12월 12일
편집: Thomas Richner 2017년 12월 12일
I too would love to multiply sparse logical matrices. I was completely surprised it wasn't implemented. The solution is to convert the smaller matrix to a sparse double with double(). Also note that sparse singles don't exist. I imagine as Matlab tries to keep pace with Deep Learning, they will need to add sparse singles, sparse logical multiplication, and half precision types.

카테고리

Help CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by