MathGroup Archive 2009

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

Search the Archive

Re: Working with Indeterminate in large numerical lists

$HistoryLength = 0;

n = 1000;

x = RandomSample[Join[RandomReal[1, 100 n],
    ConstantArray[Indeterminate, n]]];

Timing[a1 = Select[x, ! NumberQ[#] &];]


However, note that

NumberQ /@ {1, 1., Pi, E, I}


NumericQ /@ {1, 1., Pi, E, I}


So in most cases, you would want to use NumericQ rather than NumberQ

Timing[a2 = Select[x, ! NumericQ[#] &];]


Timing[a3 = Select[x, # === Indeterminate &];]


Oddly, this is faster

Timing[a4 = x[[Flatten[Position[x, Indeterminate]]]];]


Cases appears to be much more efficient than Select in this case

Timing[a5 = Cases[x, Indeterminate];]


a1 === a2 === a3 === a4 ===
 a5 === ConstantArray[Indeterminate, n]


However, for valid entries

Timing[b1 = Select[x, NumericQ];]


Timing[b2 = Cases[x, _?NumericQ];]


b1 === b2


Bob Hanlon

---- pfalloon <pfalloon at> wrote: 

Hi everyone,
I'm wondering about the optimal way to work with Indeterminate in
large matrices. I've been using this to replace "bad" data points that
I want to prevent from polluting calculations involving lists of data,
but I'm not sure I'm working as smartly as I could be.

As an example, suppose I have a list of machine-precision reals and
some Indeterminate elements:

x = RandomSample[Join[RandomReal[1, 1000], ConstantArray
[Indeterminate, 10]];

If I want to take only the valid entries, the best I have been able to
find is something like:

Select[x, NumberQ]

This seems to work reasonably well. But if I want to specifically
select the Indeterminate entries, there doesn't seem to be any
function (equivalent to, say, "isnan" from another system), so I have to
resort to something less succinct like

Select[x, #  === Indeterminate &]

Does anyone have any suggestions on better ways to do this, or any
general tips for working with Indeterminate in this context?

I'm particularly keen to do things in the most efficient way possible
as I'm working with rather large lists.


  • Prev by Date: Re: Re: new to group - Chemical Equation
  • Next by Date: Re: NDSolve with Numeric Function
  • Previous by thread: Re: Working with Indeterminate in large numerical lists
  • Next by thread: Re: Working with Indeterminate in large numerical lists