Re: Searching for embedded zeros in list
- To: mathgroup at smc.vnet.net
- Subject: [mg32156] Re: Searching for embedded zeros in list
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Sun, 30 Dec 2001 02:54:20 -0500 (EST)
- References: <a0jlsc$31m$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Mark, a = {0.98, 0.87, 0.0, 0.5, 0.25}; b = {0.9, 0.0, 0.0, 0.0, 0.0, 0.0, 0.05}; c = {0.75, 0.42, 0.10, 0.0, 0.03}; d = {0.0, 0.90, 0.75, 0.42, 0.25, 0.0}; Cases[{a,b,c,d}, {___,x_/;x=!=0.,___,0.,___,y_/;y=!=0.,___}] {{0.98,0.87,0.,0.5,0.25},{0.9,0.,0.,0.,0.,0.,0.05},{0.75,0.42,0.1,0.,0.03}} Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay at haystack.demon.co.uk Voice: +44 (0)116 271 4198 Fax: +44 (0)870 164 0565 "Coleman, Mark" <mark.coleman at dri-wefa.com> wrote in message news:a0jlsc$31m$1 at smc.vnet.net... > Greetings, > > Can anyone suggest an efficient/elegant way of checking a list for > 'embedded' zeros. By embedded I mean the occurence of one or more zeros > between two non-zero elements (note: zeros at the ends of the list are > not relevant). For instance, the following lists all contain embedded > zeros: > > a={0.98,0.87,0.0,0.5,0.25} > b={0.9,0.0,0.0,0.0,0.0,0.0,0.05} > c={0.75,0.42,0.10,0.0,0.03} > > while this list does not d={0.0,0.90,0.75,0.42,0.25,0.0} > > By way of background, I am working on a problem involving estimating > generators for Markov transition matrices. One condition that ensures > that a generator *does not* exist is the presence of inaccessible states > in any row of the matrix. Thus one need only find a single occurance of > an inaccessible state to show that a generator does not exist. Hence the > code need only locate one such state, not all of them. > > The Mathematica code I've written for this problem does work, but it is hardly > "elegant". > > Any help would be much appreciated! > > Best regards, > > -Mark > >