Effacer les filtres
Effacer les filtres

Can't multiply sparse logical matrices?

3 vues (au cours des 30 derniers jours)
Nachiketa Sahoo
Nachiketa Sahoo le 13 Juin 2012
Modifié(e) : Thomas Richner le 12 Déc 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.

Réponses (2)

the cyclist
the cyclist le 13 Juin 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 le 12 Déc 2017
Modifié(e) : Thomas Richner le 12 Déc 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.

Catégories

En savoir plus sur Sparse 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