MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: 2D pattern matching

  • To: mathgroup at smc.vnet.net
  • Subject: [mg77414] Re: [mg77264] Re: [mg77140] 2D pattern matching
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Fri, 8 Jun 2007 05:29:07 -0400 (EDT)
  • References: <200706051024.GAA00465@smc.vnet.net> <3789605.1181136409894.JavaMail.root@m35> <op.ttilxgo2qu6oor@monster.ma.dl.cox.net> <23465250.1181231392800.JavaMail.root@m35>
  • Reply-to: drmajorbob at bigfoot.com

> János
> P.S.  What has happened to DrBob ?  Did he go to the Army ? :)

I retired from the Air Force in 1995, and I started using "major" in my  
e-mail address a year ago.

I originally became DrBob because I worked for another Bobby (at Battelle  
Memorial Institute) who WASN'T a PhD. It was just to tell us apart.

And it's an easily remembered address, too.

Bobby

On Thu, 07 Jun 2007 10:29:03 -0500, János <janos.lobb at yale.edu> wrote:

> Of course if he is changing that 2x2 with a nxm where either n or m is  
> not 2, then of course he will be in trouble if he wants to do the change  
> for every 2.2 at once.
>
> As a newbie I had just 2x2-s in my mind :)
>
> Thanks,
>
> János
> P.S.  What has happened to DrBob ?  Did he go to the Army ? :)
>
> On Jun 6, 2007, at 3:33 PM, DrMajorBob wrote:
>
>> That solution indicates, initially, the need for an inverse to  
>> Partition[x_,{2,2},{1,1}] and similar things.
>>
>> After changing one of the 2x2's, though, the "blown-up" matrix isn't in  
>> the domain of that inverse.
>>
>> Bobby
>>
>> On Wed, 06 Jun 2007 06:03:31 -0500, János <janos.lobb at yale.edu> wrote:
>>
>>>
>>> On Jun 5, 2007, at 6:24 AM, alexxx.magni at gmail.com wrote:
>>>
>>>> hi everybody,
>>>>
>>>> do you know how to do a pattern match involving 2D matrices?
>>>> If e.g. you have a list
>>>>
>>>> a = {{0, 0, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 0}, {0, 1, 0, 1, 1, 0}, {0,
>>>>    0, 0, 1, 1, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}}
>>>>
>>>> i.e.
>>>> 0 0 0 0 0 0
>>>> 0 1 0 0 0 0
>>>> 0 1 0 1 1 0
>>>> 0 0 0 1 1 0
>>>> 0 0 0 0 0 0
>>>>
>>>> is it possible for me to write a rule by which I am able to find the
>>>> 2x2 square of 1's, and replace it with something else?
>>>>
>>>> I studied all I could on patterns, but didnt find an answer...
>>>>
>>>> thanks for ANY help
>>>>
>>>> Alessandro Magni
>>>>
>>>
>>> Here is a newbie bit-blow-up approach:
>>>
>>> In[2]:=
>>> b = Partition[a, {2, 2},
>>>     {1, 1}]
>>> Out[2]=
>>> {{{{0, 0}, {0, 1}},
>>>     {{0, 0}, {1, 0}},
>>>     {{0, 0}, {0, 0}},
>>>     {{0, 0}, {0, 0}},
>>>     {{0, 0}, {0, 0}}},
>>>    {{{0, 1}, {0, 1}},
>>>     {{1, 0}, {1, 0}},
>>>     {{0, 0}, {0, 1}},
>>>     {{0, 0}, {1, 1}},
>>>     {{0, 0}, {1, 0}}},
>>>    {{{0, 1}, {0, 0}},
>>>     {{1, 0}, {0, 0}},
>>>     {{0, 1}, {0, 1}},
>>>     {{1, 1}, {1, 1}},
>>>     {{1, 0}, {1, 0}}},
>>>    {{{0, 0}, {0, 0}},
>>>     {{0, 0}, {0, 0}},
>>>     {{0, 1}, {0, 0}},
>>>     {{1, 1}, {0, 0}},
>>>     {{1, 0}, {0, 0}}},
>>>    {{{0, 0}, {0, 0}},
>>>     {{0, 0}, {0, 0}},
>>>     {{0, 0}, {0, 0}},
>>>     {{0, 0}, {0, 0}},
>>>     {{0, 0}, {0, 0}}}}
>>>
>>> /If you do a MatrixForm on b you will able to see where that block
>>> is  and how you should get the staring coordinates:)/
>>>
>>> Then
>>>
>>> In[4]:=
>>> Position[b, {{1, 1}, {1, 1}}]
>>> Out[4]=
>>> {{3, 4}}
>>>
>>> gives the upper left position of the block in b and that is the same
>>> as in a.  /I leave the proof of it to the experts :)/
>>>
>>> Replacing now in a is easy because you know how many cells in right
>>> and down do you want to replace from the found starting position.
>>>
>>>
>>> J=E1nos
>>>
>>>
>>> ---------------------------------------------
>>> "Its like giving a glass of ice water to somebody in Hell"
>>> Steve Jobs about iTunes on Windows
>>>
>>>
>>>
>>>
>>
>>
>>
>> --DrMajorBob at bigfoot.com
>
>



-- 
DrMajorBob at bigfoot.com


  • Prev by Date: Re: Best practice for Mathematica package development
  • Next by Date: Re: Re: Java failure
  • Previous by thread: Re: Re: 2D pattern matching
  • Next by thread: Re: Re: 2D pattern matching