Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1995
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1995

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

Search the Archive

Re: I don't know how to ....

  • To: mathgroup at smc.vnet.net
  • Subject: [mg2460] Re: I don't know how to ....
  • From: vince at vince.math.uconn.edu (Vince Giambalvo)
  • Date: Sun, 12 Nov 1995 22:26:22 -0500
  • Organization: University of Connecticut

In article <47pm9c$fbk at ralph.vnet.net> pehowland at taz.dra.hmg.gb (Paul E Howland) writes:

   In article <471hgv$gb3 at ralph.vnet.net>, bientin at cli.di.unipi.it (Paolo Bientinesi) writes:

   |here's my problem:
   |I need  a function that takea as input a list of pairs;
   |the first element of every pair is a list, the second one is an integer;
   |I want the function to calculate thhe
   |biggest integer and to give as output the corresponding list.

   Assuming your list is like:

	   data = {{{1,2,3},0}, {{4,5,6},5}, {{7,8,9},3}}

   then the following will work:

	   In[1]:= Part[data, Position[
			   Map[#[[2]]&, data],
			   Max[Map[#[[2]]&, data]]
			   ][[1,1]], 1]
	   Out[1]= {4, 5, 6}

   Hope this helps,

I run in to lots of problems with solutions of this type, i.e, some
function of the input data is used more than once, in this case
Map[#[[2]]&,data].  I usually use a (temporary) variable to hold the
result, because I didn't think Mathematica would be smart enough to
save it and avoid recomputing. This usually involves setting up a
Module or Block, which also has overhead. Are there any guidelines for
doing this efficiently? Obviously the more complicated the function
the more expensive the recalculation, if it occurs.
       Vince





  • Prev by Date: Re: help functions
  • Next by Date: Re: turn off symbols in MultipleListPlot?
  • Previous by thread: Re: I don't know how to ....
  • Next by thread: Re: Novice user