Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #7991
| From | DrMajorBob <btreat1@austin.rr.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Is there any efficient easy way to compare two lists with the same length with Mathematica? |
| Date | 2012-01-19 10:07 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jf8q0s$3ep$1@smc.vnet.net> (permalink) |
a == b and a === b evaluate before Thread has a chance to act. The others
do not.
a < b
a > b
a == b
a === b
{1, 2, 3} < {3, 2, 1}
{1, 2, 3} > {3, 2, 1}
False
False
Bobby
On Wed, 18 Jan 2012 04:58:07 -0600, James Stein <mathgroup@stein.org>
wrote:
> I learned something from the answer(s) on this thread, leading to a
> question of my own: Why do 'Equal' and 'SameQ' respond differently
> from 'Greater' and 'Less' ? e.g.:
>
> a = {1, 2, 3};
> b = {3, 2, 1};
> Thread[a < b]
> Thread[a == b]
> Thread[a === b]
> Thread[b < a]
>
> On Tue, Jan 17, 2012 at 4:01 AM, Bill Rowe <readnews@sbcglobal.net>
> wrote:
>
>> On 1/17/12 at 3:34 AM, aoirex@gmail.com (Rex) wrote:
>>
>> >Given two lists `A={a1,a2,a3,...an}` and `B={b1,b2,b3,...bn}`, I
>> >would say `A>=B` if and only if all `ai>=bi`.
>>
>> >There is a built-in logical comparison of two lists, `A==B`, but no
>> >`A>B`. Do we need to compare each element like this
>>
>> >And@@Table[A[[i]]>=B[[i]],{i,n}]
>>
>> I think you do need to do an element by element comparison. But
>> you don't need to specifically select each element using Part as
>> you are doing. That is:
>>
>> In[13]:= {a, b} = RandomInteger[100, {2, 5}];
>> And @@ Thread[a > b]
>>
>> Out[14]= False
>>
>> In[15]:= c = RandomInteger[{150, 200}, 5];
>> And @@ Thread[c > a]
>>
>> Out[16]= True
>>
>>
>>
--
DrMajorBob@yahoo.com
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: Is there any efficient easy way to compare two lists with the same length with Mathematica? DrMajorBob <btreat1@austin.rr.com> - 2012-01-19 10:07 +0000
csiph-web