Questions on the manipulation of List objects in Mathematica, and the functions used for these manipulations.
10
votes
2answers
349 views
How do I find the elements in a list that return the highest value for a function?
Suppose we have a list of values and a function f. I want to find which of the elements maximizes the return value of the function in Mathematica. Let call the ...
12
votes
6answers
557 views
Splitting up delimited data in lists
One task that I frequently find myself doing in Mathematica is splitting lists into lists of sublists, using specific elements to define the break-points. This is particularly useful with imported ...
7
votes
2answers
171 views
How can I get the list of dates in the next $n$ years
How can I get the list of all dates from today 21.02.2012 (which is a palindrome) up to say next $n$ years? Then finding the other palindromes are not difficult. I could not find an easy way to ...
2
votes
3answers
944 views
Product of elements within a list
Please Consider :
list={{5,2,6},{2,8,3}}
I need to get the product of all the element within list :
As of now I do this :
...
16
votes
7answers
810 views
How to Derive Tuples Without Replacement
Given a couple of lists like a={1,2,3,4,6} and b={2,3,4,6,9} I can use the built-in Mathematica symbol ...
4
votes
3answers
166 views
Transform vector with lag
Say I have a vector $Z_n$ with and I want to transform it into another vector using this formula:
$X_t=Z_t+0.7Z_{t-2}$
The problem is that I am not quite sure how to get that $t-2$ lag in there. I ...
9
votes
4answers
655 views
How to sum up subelements of a list of unknown length
I'm simply looking for the {}+{} function for sublist elements of a list: (Parallel sums of elements)
...
9
votes
5answers
278 views
Finding time-series direction reversal of certain magnitude
I'd like to find the points of a time-series that are a certain distance away (in value, not in time) from the previous maximum, which I consider a reversal.
For example, for ...
2
votes
1answer
155 views
List of different values which have to be formatted differently
I have a large list of values which – for presentation in my LaTeX document – I need to format. For instance: I have calculated growth rates which I now would like to have formatted in the form of:
...
12
votes
9answers
411 views
Generating a matrix using sublists A and B n times
I want to write a function that generates a square matrix from sublists. My sublists are
a = Range[0, x, 0.5]; b = Range[0.25, x + 0.25, 0.5];
Suppose x=2, then I ...
3
votes
3answers
861 views
How to change step size of ListPlot
The command ListPlot will plot lists with a unit step. Is there any way to change the step size of this?
5
votes
4answers
211 views
9
votes
3answers
352 views
Most Efficient Way to Calculate the Product of All Items in a List?
Say that I have a list of returns on a financial asset over time and want to know the total compounded return. To get the answer, I need to add 1 to each return and then calculate the product of all ...
13
votes
7answers
605 views
Selecting a sublist based on Length
If you have a simple list of lists as follows:
test = {{1, 2}, {4, 5, 6, 7}, {5, 4, 3}}
How do you ask Mathematica to return the sublist of greatest length?
...
12
votes
8answers
427 views
How to neatly get the sum of symmetric elements in a list?
The task is to compute
symmSum[{a, b, c, d, e, f}]
(*==> {a+f, b+e, c+d} *)
symmSum[{a, b, c, d, e}]
(*==> {a+e, b+d, c} *)
My clumsy solution is
...
13
votes
4answers
325 views
How can I remove B -> A from a list if A -> B is in the list?
I have a list of transformations like this:
list = {"A" -> "B", "B" -> "A", "C" -> "D"}
As this is used to plot an undirected graph with ...
8
votes
4answers
218 views
Check in a series if there exists adjacent values with less than a certain number of missing values
I'm working with a large number of series of different experiments, where there exist a lot of experiments where there are no entries. I now want to draw a sample where there should exist at least ...
12
votes
5answers
1k views
How to Delete Elements from List1 appearing in List2?
I'm new to functional programming of Mathematica and trying to remove one list of assorted elements from another. However I only find functions working with the Index rather than the values itself:
...
9
votes
3answers
248 views
Permutations[Range[12]] produces an error instead of a list
This input:
Permutations[Range[12]]
Results in this (error) output:
...
17
votes
7answers
686 views
Selectively Mapping over elements in a List
I am using the following code to easily generate a row of images of all eight planets of our Solar System:
...
5
votes
1answer
124 views
Bug in LengthWhile?
Is this a bug or my MMA went insane or I'm missing something?
LengthWhile[Reverse@IntegerDigits[1000], # == 0 &]
works fine, but with SameQ instead of Equal, ...
18
votes
6answers
772 views
efficient way to count the number of zeros at the (right) end of a very large number
If I want to count the number of zeros at the (right) end of a large number, like $12345!$, I can use something like:
Length[Last[Split[IntegerDigits[12345!]]]]
...
14
votes
6answers
481 views
On generalizing Partition[] (with offsets) to sublists of unequal length
The usual Partition[] function is a very handy little thing:
...
11
votes
7answers
1k views
Combination and Permutation
How could I obtain the list of all the groups of 5 numbers taken from Range[12] such that the 2 lists have an empty intersection :
...
5
votes
2answers
506 views
Finding a subsequence in a list
I have a list and I want to find (in this particular case the first) appearance of a any of some subsequences, of possible different lengths. None of the subsequences is a subsequence of each other.
...
7
votes
5answers
751 views
How to find rows that have maximum value?
Suppose if I have following list
{
{10,b,30},
{100,a,40},
{1000,b,10},
{1000,b,70},
{100,b,20},
{10,b,70}
}
How to find rows that have max value in ...
10
votes
2answers
304 views
Flatten at a certain level
In an earlier question the brainteasing fourth syntax variant of Flatten was discussed. I see that with
...
4
votes
2answers
327 views
Why don't * and ^ work as I expected on matrices?
For example, this input...
{{1, 2}, {3, 4}}*{{1, 2}, {3, 4}}
produces this output...
{{1, 4}, {9, 16}}
and this input...
...
7
votes
4answers
236 views
Unexpected behavior from GatherBy in version 7
I have come across what appears to be a bug in GatherBy. It appears similar to the problem of using Table[Random[], {1000}] in ...
7
votes
2answers
178 views
How to generate Intervals from a given list?
If I have a list
list={3,7,4,5,1}
how to get the List of Intervals /Ranges
result = {{1,3},{3,4},{4,5},{5,7}}
10
votes
9answers
404 views
How to find range in which a number falls, from given list of numbers?
How can one find the range in which a number falls, from given list of numbers?
...
14
votes
6answers
337 views
Elegantly pairing up mismatched lists
HistogramList returns a list of bin boundaries and a list of counts. There is one more boundary than counts, and I'd like to pair them up so I can feed it into ...
13
votes
3answers
408 views
Efficient way to combine SparseArray objects?
I have several SparseArray objects, say sa11, sa12, sa21, sa22, which I would like to combine into the equivalent of {{sa11, sa12}, {sa21, sa22}}.
As an example, I ...
19
votes
5answers
962 views
What is the most efficient way to add rows and columns to a matrix?
Say I have a matrix m and a vector v.
...
12
votes
6answers
2k views
How to find the position of elements in a list satisfying criteria
Say I have a list x={2,4,6,8,10} and I want to find out the positions of the elements that are greater than 7.
...
9
votes
5answers
428 views
How do you efficiently return all of a List but one element?
I have a problem that I am working on that requires that I compare several lists of overlapping data points. As I traverse one of the lists, I'd like to only compare those data to the other lists, and ...
12
votes
7answers
376 views
How to use Union on list of lists without sorting them first?
If I do
ClearAll[a, d]
lsts = {{a, d}, {a, d}};
Union[lsts]
I get the expected answer
{{a, d}}
but if I do
...


