Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Re: [mg4180] How can this MapAt application be done more efficiently
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Jens-Peer Kuska

Posts: 12
Registered: 12/7/04
Re: [mg4180] How can this MapAt application be done more efficiently
Posted: Jun 16, 1996 2:09 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

> I have written a function to Drop any zero's from a table of numbers.
> Here is an example:
>
> In[161]:= dropzero[ {{5, 0}, {4, 1}, {3, 2, 0}, {3, 1, 1}} ]
>
> Out[161]= {{5}, {4, 1}, {3, 2}, {3, 1, 1}}


Hi Joel,

With
In[]:=
lst={{1,2,0,5,0},{4,6},{0,0,3,4,6,0}};

Try

In[]:=

lst //. {a___,0,b___} :> {a,b}

Out[]=
{{1, 2, 5}, {4, 6}, {3, 4, 6}}


to remove all zeros and
try

lst //. {a___,0} :> {a}

to remove only zeros at the end of every list.

Hope that helps

Jens










Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.