问题
I have a list in maxima like:
x:[1,3,7,98,211,3,2.44,23]
I need to find the maximun value of the list and on which position(s) the maximum value is situated.
The only thing that has occurred to me is to rewrite the list as a sequence and apply the 'max' command
max(first(x),second(x),...,last(x))
But it is not efficient, and I don't know get the index of the maximum value.
Can anybody help me?
回答1:
lmax
returns the maximum value of a list. Given x
is a list, then
lmax(x)
returns its minimum value.
Getting the index of the maximum value is a little more involved. The most relevant built-in function (unless I'm forgetting something -- could happen) is sublist_indices
, which returns the indices of the elements which satisfy a predicate. The predicate is a function of one variable which returns true or false. To continue the example, `
sublist_indices(x, lambda([x1], x1 = lmax(x)))
returns one or more indices at which the elements of x
take on the maximum value.
来源:https://stackoverflow.com/questions/43714455/find-maximum-value-and-index-in-a-maxima-list