Re: Re: 2D pattern matching
- To: mathgroup at smc.vnet.net
- Subject: [mg77381] Re: [mg77264] Re: [mg77140] 2D pattern matching
- From: DrMajorBob <drmajorbob at bigfoot.com>
- Date: Thu, 7 Jun 2007 04:04:05 -0400 (EDT)
- Organization: Deep Space Corps of Engineers
- References: <200706051024.GAA00465@smc.vnet.net> <3789605.1181136409894.JavaMail.root@m35>
- Reply-to: drmajorbob at bigfoot.com
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
- References:
- 2D pattern matching
- From: "alexxx.magni@gmail.com" <alexxx.magni@gmail.com>
- 2D pattern matching