Reputation: 1603
Let's say that I had a Maxima list of indices, say indexlist = [1,3,5]
,
and a list of values, for example valuelist = [1,2,3,4,5]
. What is the syntax for choosing the elements of valuelist
based on the indices in indexlist
on a single line? I've tried
values : valuelist[indexlist]; /*Should return [1,3,5]*/
which obviously didn't work since I'm feeding a list to the selection operator []
, that expects a nonnegative integer.
Upvotes: 0
Views: 267
Reputation: 17576
There isn't a built-in syntax for that. The idiom which I usually use is:
somevals : makelist (valuelist[i], i, indexlist);
Note that values
is a built-in global variable; it is the list of symbols which have values assigned to them. See ? values
and maybe also ? infolists
.
Upvotes: 1