Azzera filtri
Azzera filtri

Can't multiply sparse logical matrices?

3 visualizzazioni (ultimi 30 giorni)
Nachiketa Sahoo
Nachiketa Sahoo il 13 Giu 2012
Modificato: Thomas Richner il 12 Dic 2017
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.

Risposte (2)

the cyclist
the cyclist il 13 Giu 2012
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 il 12 Dic 2017
Modificato: Thomas Richner il 12 Dic 2017
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.

Categorie

Scopri di più su Sparse Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by