Search All of the Math Forum:

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

Topic: ReplacePart -> eliminate
Replies: 1   Last Post: Sep 17, 2013 9:33 PM

 Bob Hanlon Posts: 906 Registered: 10/29/11
Re: ReplacePart -> eliminate
Posted: Sep 17, 2013 9:33 PM

x = {-1.25664, 0.628319, -0.628319, 1.25664, Indeterminate, -1.25664,
0.628319, -0.628319, 1.25664, Indeterminate, 1/3, 1/2, 1,
ComplexInfinity, -1, -1/2};

To eliminate them

numOnly = Select[x, NumericQ]
{-1.25664, 0.628319, -0.628319,
1.25664, -1.25664, 0.628319,
-0.628319, 1.25664, 1/3, 1/2,
1, -1, -(1/2)}

Alternatives:

numOnly == Cases[x, _?NumericQ] ==
DeleteCases[x, _?(! NumericQ[#] &)] ==
Pick[x, NumericQ[x]]

True

To replace them with 0

(# /. _?(! NumericQ[#] &) -> 0) & /@ x

{-1.25664, 0.628319, -0.628319,
1.25664, 0, -1.25664,
0.628319, -0.628319, 1.25664,
0, 1/3, 1/2, 1, 0, -1, -(1/2)}

Bob Hanlon

On Mon, Sep 16, 2013 at 4:04 AM, Brambilla Roberto Luigi (RSE) <
Roberto.Brambilla@rse-web.it> wrote:

> I'd like to eliminate the Indeterminate (or other non-numerical terms,
> as Infinite, etc...) items. Es.
>
>
> x = {-1.25664, 0.628319, -0.628319, 1.25664, Indeterminate, -1.25664,
> 0.628319, -0.628319, 1.25664, Indeterminate};
>
> or
>
> x=Table[1/(3 - n), {n, 0, 5}])
> {1/3, 1/2, 1, ComplexInfinity, -1,-1/2}
>
> How can I do it with a simple command?
> Many thanks, Roberto
>
> -----Messaggio originale-----
> Da: Bob Hanlon [mailto:hanlonr357@gmail.com]
> Inviato: domenica 15 settembre 2013 13:06
> A: mathgroup@smc.vnet.net
> Oggetto: Re: ReplacePart
>
>
> {5,10} is apparently interpreted as a position within an array rather
> than a list of positions. Not sure why the algorithm isn't able to
> resolve the ambiguity given that the input is a simple list. Or why
> there is no error stating that position {5,10} does not exist.
>
>
> x = {-1.25664, 0.628319, -0.628319, 1.25664, Indeterminate, -1.25664,
> 0.628319, -0.628319, 1.25664, Indeterminate};
>
>
> x2 = x /. Indeterminate -> 0
>
>
> {-1.25664, 0.628319, -0.628319, 1.25664, 0, -1.25664, 0.628319,
> -0.628319, \ 1.25664, 0}
>
>
> x2 ==
> ReplacePart[x, {5 -> 0, 10 -> 0}] ==
> ReplacePart[x, Thread[{5, 10} -> 0]] == ReplacePart[x, {{5} -> 0, {=

10}
> -> 0}] == ReplacePart[x, {{5}, {10}} -> 0] == ReplacePart[x, Li=
st /@
> {5, 10} -> 0] == ReplacePart[x, Position[x, Indeterminate] -> 0]
>
>
> True
>
>
>
> Bob Hanlon
>
>
>
>
> On Sat, Sep 14, 2013 at 6:02 AM, man21 <man21@free.fr> wrote:
>

> > Hello,
> >
> > As a result of a calculation, I end up with a list of numerical values

>
> > which contains some "Indeterminate".
> >
> > x ={-1.25664, 0.628319, -0.628319, 1.25664, Indeterminate, -1.25664,
> > 0.628319, -0.628319, 1.25664, Indeterminate}
> >
> > I try to replace the "Indeterminate" by "0", using :
> >
> > ReplacePart[x, {5, 10} -> 0.]
> >
> > but this dosen't work. Any idea why, and how to do it ?
> >
> > Thanks,
> >
> > Michel
> >
> >
> >

>
>
> RSE SpA ha adottato il Modello Organizzativo ai sensi del D.Lgs.231/2001,
> in forza del quale l'assunzione di obbligazioni da parte della Societ=E0
> avviene con firma di un procuratore, munito di idonei poteri.
> RSE adopts a Compliance Programme under the Italian Law (D.Lgs.231/2001).
> According to this RSE Compliance Programme, any commitment of RSE is take=

n
> by the signature of one Representative granted by a proper Power of
> Attorney. Le informazioni contenute in questo messaggio di posta
> elettronica sono riservate e confidenziali e ne e' vietata la diffusione =

in
> qualsiasi modo o forma. Qualora Lei non fosse la persona destinataria del
> presente messaggio, La invitiamo a non diffonderlo e ad eliminarlo, dando=

ne
> gentilmente comunicazione al mittente. The information included in this
> e-mail and any attachments are confidential and may also be privileged. I=

f
> you are not the correct recipient, you are kindly requested to notify the
> sender immediately, to cancel it and not to disclose the contents to any
> other person.
>