Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

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

Search the Archive

Re: question on Max and Min

  • To: mathgroup at smc.vnet.net
  • Subject: [mg80989] Re: question on Max and Min
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Fri, 7 Sep 2007 02:05:00 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <fbojr2$jeo$1@smc.vnet.net>

Arkadiusz.Majka at gmail.com wrote:

> Please take o while and think if
> 
> Max[longList]-Min[longList]
> 
> is the fastest way of calculating the difference of maximal and
> minimal values of (very) long list.

I would say yea for a one-dimensional list made of homogeneous atomic 
elements (i.e. all element have the same basis type such as machine-size 
floating-point numbers or integers).

The following example tests a vector of 100 million floating-point 
numbers (occupying about 800 Mo in RAM) in less than 0.9 second. To me, 
I would say the list is very large and the test fast enough. Of course, 
you may have a different opinion. Also, sorting the list before talking 
the first and last elements is much slower even when using Ordering. (I 
believe that Max and Min have been optimized to work fast on large list.)

In[1]:= longList = RandomReal[{-10000, 10000}, {10^8}];
ByteCount[longList]
Max[longList] - Min[longList] // Timing

Out[2]= 800000076

Out[3]= {0.875, 20000.}

-- 
Jean-Marc





  • Prev by Date: Re: Mathematica 6 specific Import[ ] problem
  • Next by Date: Re: Mathematica 6 specific Import[ ] problem
  • Previous by thread: question on Max and Min
  • Next by thread: Log of y-axis data?