Re: 2D pattern matching
- To: mathgroup at smc.vnet.net
- Subject: [mg77252] Re: 2D pattern matching
- From: dh <dh at metrohm.ch>
- Date: Wed, 6 Jun 2007 06:57:18 -0400 (EDT)
- References: <f43dm5$f8$1@smc.vnet.net>
Hi Alex, As your patterns spans more than one row, you must specify a global pattern for the whole array, Therefore, if you have more than one block of "1" you must use ReplaceRepeated. E.g. asssuming your array is in a: a//.{x1:{__}..,{y1:___,1,1,y2___},{z1:___,1,1,z2___},x2:{__}..}->{x1,{y1,a1,a2,y2},{z1,a3,a4},x2} hope this helps, Daniel 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 > >