|
[Date Index]
[Thread Index]
[Author Index]
Re: I don't know how to ....
- Subject: [mg2460] Re: I don't know how to ....
- From: vince at vince.math.uconn.edu (Vince Giambalvo)
- Date: Mon, 13 Nov 1995 03:26:22 GMT
- Approved: usenet@wri.com
- Distribution: local
- Newsgroups: wri.mathgroup
- Organization: University of Connecticut
- Sender: daemon at wri.com ( )
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:
question: {a,b,c}->{{a,b},{b,c}}??
Next by Date:
turn off symbols in MultipleListPlot?
Previous by thread:
Re: I don't know how to ....
Next by thread:
Re: I don't know how to ....
|