Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2001
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2001

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

Search the Archive

Re: Re: Searching for embedded zeros in list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg32158] Re: [mg32145] Re: [mg32136] Searching for embedded zeros in list
  • From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
  • Date: Sun, 30 Dec 2001 02:54:23 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Something strange happened to this message in passage through the 
Internet and what I got back was not what I sent.  The code for 
EmbeddedZeros should have been:

In[1]:=
EmbeddedZeros[l_List] := Module[{u = N[l]},
    ReplaceList[u, {___, x_, v:(0...), y_, ___} :>
      RuleCondition[{x, v, y}, x != 0 && y != 0]]]

Andrzej Kozlowski
Toyama International University
JAPAN
http://platon.c.u-tokyo.ac.jp/andrzej/

On Sunday, December 30, 2001, at 08:00  AM, Andrzej Kozlowski wrote:

> Since you do not let us know your "inelegant" code I can't be sure that
> you will consider mine more elegant.
> However, here it is:
>
> In[1]:=
> EmbeddedZeros[l_List]:=
>    Module[{u=N[l]},
>      ReplaceList[
>        u,{___,x_,v:Repeated[0.0],y_,___}:>
>          RuleCondition[{x,v,y},x?â?0&&y?â?0]]]
>
> In[2]:=
> a={0.75,0.,0,0.42,0.10,0.0,0.03};
>
> In[3]:=
> b={0.0,0.90,0.75,0.42,0.25,0.0};
>
> In[4]:=
> EmbeddedZeros[a]
>
> Out[4]=
> {{0.75,0.,0.,0.42},{0.1,0.,0.03}}
>
> In[5]:=
> EmbeddedZeros[b]
>
> Out[5]=
> {}
>

>
> On Saturday, December 29, 2001, at 02:46  PM, Coleman, Mark wrote:
>
>> 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
>>
>>
>>
>>
>
>
>
>



  • Prev by Date: Re: Searching for embedded zeros in list
  • Next by Date: Re: Re: Front end problems!
  • Previous by thread: Re: Searching for embedded zeros in list
  • Next by thread: 3dplots again