Tagged Questions

Questions on the manipulation of List objects in Mathematica, and the functions used for these manipulations.

learn more… | top users | synonyms (3)

21
votes
5answers
1k views

Partition a set into subsets of size $k$

Given a set $\{a_1,a_2,\dots,a_{lk}\}$ and a positive integer $l$, how can I find all the partitions which includes subsets of size $l$ in Mathematica? For instance, given ...
18
votes
1answer
755 views

How can the {x,y,z} points that fall on the outer boundary of a set of values be selected and smoothly surfaced?

For a given set of x,y,z values, that may, or may not form a uniform shape, how can the center of the data cloud be found, and the surface points be located and a solid smooth surface created from ...
2
votes
2answers
2k views

Creating Lists From Loops

Consider the following: lists = Import["G:/Notebooks/Lists.csv"]; col7 = lists [[All, 7]]; For[i=0,i<101,i++,Print[Count[col7,i]]] This will get a 100 cells ...
9
votes
5answers
257 views

Fill out blanks with a upcoming number in a list?

I have a bunch of arrays looking like this: {"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ...
3
votes
1answer
278 views

n-fold symbolic integral in Mathematica

I am trying to compute symbolically a n-fold integral (n is a parameter of a function) over, say, the cube [0,a]^n. My code looks like this ...
4
votes
1answer
201 views

What's the most intelligent way to store the information of a selfmade graph?

I have a very long list of element, say $a1,a2, a3$,..., and they are all connected in that each is the child of many parents. E.g. $a74$ is associated with $a2,a55,a71$, and also contains ...
4
votes
1answer
310 views

Defining a string based sort function

I'm having a bit of trouble figuring out the right Sort syntax to use on a list of lists. Consider the following list: ...
42
votes
6answers
3k views

Does Mathematica have advanced indexing?

I have two $M \times K$ arrays $L, T$ where I would like to set all the elements in $L$ to zero whenever the corresponding element of $T$ is greater than 15. The ...
9
votes
4answers
4k views

How can I multiply matrix and vector element wise like Numpy?

I have an $M \times K$ matrix $C$ and a length $K$ vector $v$. I want to form the $M \times K$ matrix $S$ where $s_{ij} = C_{ij}/v_j$. To do this in numpy I simply divide the two objects like this ...
4
votes
1answer
372 views

Deleting parts of a large list

At present I am running an analysis on economic data. Within the data I was able to identify countries which went through recession. I then calculated for example the average decline rate of GDP ...
16
votes
1answer
337 views

Are there advantages to using additional arguments of common functions rather than alternative ways of calculating with lists?

(Apologies for the long question title.) One of the interesting, if sometimes confusing, things about Mathematica is that there is always more than one way to do things. Even intermediate users can ...
26
votes
4answers
1k views

Clustering of space-time data

Below is an example of a gaze sequence I recorded during a 3 seconds display. That is, where the eye was at every millisecond. While we should have 3000 points, we are missing some due to blinking. ...
9
votes
7answers
384 views

How to efficiently Append a result of an operation on each element of a list to itself

I'm looking for the best function to apply the product of the last two elements of sublist elements to each element: Example: ...
10
votes
4answers
715 views

Efficiently Visualising Very Large Data Sets (without running out of memory)

I have put a few really hard problems in combinatorics up against Mathematica 8. I'd have to say that it works really well, until you want to view the data. If you look at my question Advanced ...
15
votes
4answers
1k views

What is the right way to rotate an array?

Suppose I have an array, not necessarily square: a = $\left( \begin{array}{ccc} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{array} \right)$ I want to rotate it like one ...
2
votes
1answer
234 views

Conditional Data Selection, efficiency

Building up on the solution proposed here : Simplifying nested If statements You can find here the data set : allGazes.dat ...
8
votes
5answers
359 views

How to distinguish between lists and values?

I have a (hopefully small) problem with some numerical integration algorithm, more specifically I want to integrate the imaginary part of a complex valued function, e.g. ...
4
votes
4answers
2k views

Delete duplicate elements from a list

If a list contains duplicate elements, for example list = {a, 1, 5, 3, 5, x^2, x^2}, how can the duplicate elements be removed? The result would be ...
15
votes
6answers
2k views

Max of a table/list with indeterminate values

Suppose I have a Table: tab = {1., 2., 3., Indeterminate} When I type Max[tab] I get ...
13
votes
5answers
2k views

Finding all elements within a certain range in a sorted list

Suppose we have a sorted list of values. Let's use list = Sort@RandomReal[1, 1000000]; for this example. I need a fast function ...
4
votes
1answer
630 views

How to create a histogram of annual events, such as cherry blossom time

I have calculated blooming and ripening times for a specific variety of plant, based on actual temperature data from over 40 years. I would like to create two histograms on a single axis; one for ...
7
votes
6answers
1k views

Simplifying nested If statements

Consider : list = {100,102,103,99,106,107,104,112} I want to consider, extract only the "big moves" of that time series. In this case the moves bigger then 5 ...
12
votes
2answers
1k 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 ...
13
votes
6answers
946 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
219 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 ...
3
votes
3answers
3k 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 : ...
21
votes
7answers
1k 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
234 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
1k 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
365 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
178 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
447 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
2k 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
236 views

Take off {} using Position []

Please consider : ...
9
votes
3answers
1k 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 ...
14
votes
7answers
1k 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? ...
14
votes
8answers
523 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 ...
15
votes
6answers
447 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
274 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 ...
19
votes
5answers
2k 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: ...
12
votes
5answers
573 views

Permutations[Range[12]] produces an error instead of a list

This input: Permutations[Range[12]] Results in this (error) output: ...
19
votes
8answers
1k 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: ...
6
votes
1answer
148 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, ...
23
votes
6answers
1k 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!]]]] ...
17
votes
6answers
773 views

On generalizing Partition[] (with offsets) to sublists of unequal length

The usual Partition[] function is a very handy little thing: ...
11
votes
7answers
2k 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 : ...
12
votes
1answer
1k 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. ...
9
votes
5answers
2k 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 ...
9
votes
2answers
707 views

Flatten at a certain level

In an earlier question the brainteasing fourth syntax variant of Flatten was discussed. I see that with ...
8
votes
3answers
954 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... ...