Can't multiply sparse logical matrices?

2 次查看(过去 30 天)
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