Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Handling conditions on subvector elements
Replies: 6   Last Post: Mar 23, 2011 3:03 AM

 Messages: [ Previous | Next ]
 Lengyel Tamas Posts: 10 Registered: 2/23/11
Re: Handling conditions on subvector elements
Posted: Mar 23, 2011 3:03 AM

Thank you so much for your replies.

Patrick: I have filtered those triplets you mentioned where the third
element may be equal with any of the others.
Andy: my arrays probably will be large (thousands of elements), so I will
Jf: Thank you. I will try to compare Timing on the methods.

Thank you all again!

Tamas

> Hi,
>
> your condition is not really clear since it is not expressed, what
> should happen in the case of {1,2,2}. But I assume that should help you
> anyway
>
> v = {{1, 1, 2}, {1, 1, 3}, {2, 3, 1}, {1, 2, 3}, {3, 3, 1}}
> v /. {a_, b_, c_} :> Which[a === b && b =!= c, 1, True, 2]
>
> Out[5]= {{1, 1, 2}, {1, 1, 3}, {2, 3, 1}, {1, 2, 3}, {3, 3, 1}}
>
> Out[6]= {1, 1, 2, 2, 1}
>
>
> Cheers
> Patrick
>
>
> On Tue, 2011-03-22 at 05:05 -0500, Lengyel Tamas wrote:

>> Dear Mathworld users,
>>
>> I am struggling with a piece of code which should result in a List :
>>
>> 1) I have a vector with subvectors with triplets of values.
>> 2) What I wish to achieve is a cycle that returns with a List with
>> either
>> '1's or '2's in it.
>> 3) The cycle should check whether the first and second element in
>> subvectors are equal and neither of them are equal with the third, if
>> so,
>> return 1;
>> If all the elements are unequal, return 2
>>
>> E.g.
>>
>> V= {{1,1,2},{1,1,3},{2,3,1},{1,2,3},{3,3,1}} should return with {1, 1,
>> 2,
>> 2,1}
>>
>> I'm assuming 'If' should be the key (as it returns 2 types of values),
>> but
>> I can't seem to do it properly.
>>
>>
>> Tamas
>>

>
>
>

Date Subject Author
3/22/11 Lengyel Tamas
3/23/11 DrMajorBob
3/23/11 Patrick Scheibe
3/23/11 Bill Rowe
3/23/11 Bob Hanlon
3/23/11 Lengyel Tamas
3/23/11 Peter Breitfeld