MathGroup Archive 2009

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

Search the Archive

Re: put some elements to zero

  • To: mathgroup at smc.vnet.net
  • Subject: [mg101491] Re: put some elements to zero
  • From: dr DanW <dmaxwarren at gmail.com>
  • Date: Wed, 8 Jul 2009 07:13:59 -0400 (EDT)
  • References: <h2vcj8$qq7$1@smc.vnet.net>

At it's heart, Mathematica is a very efficient pattern matcher, so if
you can think of a pattern that matches only the expressions you want
to effect, then take advantage of the built-in matching system.  Your
criteria are pretty clearly spelled out already, so the code writes
itself, for example:

table /. {(xi_)?(# < 0.5 &), yi_} :> {xi, 0}

or

table /. {xi_, yi_} :> {xi, 0} /; xi < 0.5

Some people who are not used to the programming-with-punctuation style
may prefer the partially spelled-out version:

ReplaceAll[table, {xi_, yi_} :> Condition[{xi, 0}, xi < 0.5]]

Look up tutorial/PuttingConstraintsOnPatterns in the Documentation
Center.


  • Prev by Date: Re: Pattern matching / subsequence matching, question on example in
  • Next by Date: Re: Jens-Peer Kuska passed away
  • Previous by thread: Re: put some elements to zero
  • Next by thread: Re: put some elements to zero