MathGroup Archive 2007

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

Search the Archive

Re: 2D pattern matching

  • To: mathgroup at smc.vnet.net
  • Subject: [mg77232] Re: 2D pattern matching
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Wed, 6 Jun 2007 06:46:47 -0400 (EDT)
  • Organization: Uni Leipzig
  • References: <f43dm5$f8$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de

Hi,
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}}

and

a /. {top___, {a___, 1, 1, b___}, {c___, 1, 1, d___}, bottom___} /;
    Length[{a}] === Length[{c}] :>
   {top, {a, this, is, b}, {c, "a 2d", pattern, d}, bottom}

will do it.

Regards
   Jens

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
> 
> 


  • Prev by Date: How to show the plot in Module[{}, ]?
  • Next by Date: Re: Trouble with TraditionalForm in Mathematica 6.0
  • Previous by thread: Re: 2D pattern matching
  • Next by thread: Re: 2D pattern matching