Re: Working with Indeterminate in large numerical lists
- To: mathgroup at smc.vnet.net
- Subject: [mg100241] Re: Working with Indeterminate in large numerical lists
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Fri, 29 May 2009 20:56:32 -0400 (EDT)
On 5/28/09 at 4:28 AM, pfalloon at gmail.com (pfalloon) 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 &] If the goal is to select the non-numeric entries there are a number of ways to do so in addition to what you show above. When you do Select[x, NumberQ] what you are doing is using shorthand for Select[x, NumberQ@#&] You can use essentially this same syntax to get the non-numeric entries by simply negating the selection criteria, i.e. Select[x !NumberQ@#&] or instead of Select you can use Cases, i.e., Cases[x, Indeterminate] But it seems to me the only reason to select the non-numeric entries would be to remove them from other computations. This can be directly done using say DeleteCases. For example, DeleteCases[x, Indeterminate] will eliminate the Indeterminate entries One other thing to keep in mind. Using NumberQ will not select things like Pi which have numeric values. That is In[7]:= Select[{Pi, E}, NumberQ] Out[7]= {} In general for selecting numeric values you want to use NumericQ instead of NumberQ, i.e., In[8]:= Select[{Pi, E}, NumericQ] Out[8]= {Pi, E}