Re: Fast matrices comparison

• To: mathgroup at smc.vnet.net
• Subject: [mg115927] Re: Fast matrices comparison
• From: DrMajorBob <btreat1 at austin.rr.com>
• Date: Wed, 26 Jan 2011 05:05:00 -0500 (EST)

```Anybody know where these properties are documented? I guarantee they're
not mentioned in the Documentation directory.

m1 = {{8, 7}, {3, 9}};
m2 = {{2, 3}, {4, 5}};
sm1 = SparseArray[m1 - m2];
sm1["Properties"]

"PatternArray", "Properties"}

Bobby

On Tue, 25 Jan 2011 05:30:39 -0600, Oliver Ruebenkoenig
<ruebenko at wolfram.com> wrote:

> On Tue, 25 Jan 2011, JJ wrote:
>
>> Hi MathGroup
>>
>> I have to compare two big matrices (in the SparseArray form), say m1
>> and m2.
>> I need that the elements of m1 will be replaced by 0 if they are less or
>> equal to
>> the corresponding elements of m2.
>>
>> For example, if m1={{8,7},{3,9}} and m2={{2,3},{4,5}},
>> I would like to have m1={{8,7},{0,9}} because m1[[2,1]]<m2[[2,1]].
>>
>> I can do it easily with two nested for loops but I think it is not an
>> efficient way to do it.
>> I was wondering if somebody knows how to do it using a fast conditional
>> replacement rule and/or pure functions.
>>
>> Thank you.
>>
>>
>>
>
>
> JJ,
>
>
> m1 = {{8, 7}, {3, 9}};
> m2 = {{2, 3}, {4, 5}};
> sm1 = SparseArray[m1];
> sm2 = SparseArray[m2];
> v1 = sm1["NonzeroValues"];
> v2 = sm2["NonzeroValues"];
> SparseArray[sm1["NonzeroPositions"] -> v1*UnitStep[v1 - v2 - 1]];
>
> Oliver
>

--
DrMajorBob at yahoo.com

```

• Prev by Date: Re: Fast matrices comparison
• Next by Date: Re: CUDADot[] does not work with rectangular matrices
• Previous by thread: Re: Fast matrices comparison
• Next by thread: disable default Dynamic Updating Enabled