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

learn more… | top users | synonyms (3)

13
votes
11answers
883 views

How to get list of duplicates when using DeleteDuplicates?

This might be easy, but can't find a way to use DeleteDuplicates to get also list of the actual duplicates. Example: ...
14
votes
1answer
213 views

Ordering function with recognition of duplicates

Fairly often I have a need to get the Ordering of an expression but with recognition of duplicates. For example: ...
19
votes
3answers
674 views

DeleteDuplicatesBy is not performing as I'd hoped. Am I missing something?

Déjà vu: a new-in-v10 function should provide a better solution to an old problem, but my enthusiasm is curbed when I run timings. This time the function is ...
14
votes
4answers
557 views

“Unflattening” a list

Imagine we have a list with some hierarchical structure: list = {{{2,3},{2,4}},{{{3,4}}},{{5,6},{7,8}}}; Which we then flatten to some level in order to process ...
8
votes
3answers
547 views

how to efficiently apply function to all pairs of a set (and collect the results)

To build a graph, I need to apply a function f[a_, b_] to all pairs of a list (3500 elements). The function itself returns a link ...
21
votes
2answers
2k views

Extracting values from nested rules in JSON data

I have been using Mathematica to analyse some data from the StackExchange API. It is conveniently available in JSON form, which Mathematica interprets as replacement rules. However, some of the rules ...
17
votes
6answers
2k views

Best way to extract values from a list of rules?

Mathematica has a lot of list manipulation functions, and, also because I don't work with lists often, at times I'm a bit lost. I'll find a way, but I'm sure it's not the most efficient. Case in ...
10
votes
8answers
2k views

Map and Apply a function on a nested list

I have a list like this: {{1,2}, {4,2}, {6,4} ... } I want to replace every second number with a function of that number. For e.g. ...
7
votes
5answers
313 views

Manipulating a sublist based on position

I have a huge list with huge sublists of the form list={{a,b,c,d},{e,f,g,h},{i,j,k,l}} I am looking for a way to manipulate these sublists based on the positions ...
10
votes
6answers
636 views

How to Map a subset of list elements to a function?

How would you, given a list {1, 2, 3, 4}, apply a function f to 1 and ...
36
votes
3answers
1k views

Tiling a square

I wondered if there was a way to automate the process of finding a way to tile a tile into a square. The idea is to represent the tile with a matrix of $0$s for blank space and $1$s for filled spaces ...
19
votes
4answers
667 views

Accessing list elements by name

First, a bit of a long introduction to my problem: I only have a few weeks of Mathematica experience. I am creating a mathematica application that calculates some material properties of steel based ...
12
votes
7answers
968 views

How to Set parts of indexed lists?

I would like to assign a list to an indexed variable and then change it using Part and Set like this: ...
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: ...
14
votes
4answers
633 views

Implementing a function which generalizes the merging step in merge sort

One of the key steps in merge sort is the merging step. Given two sorted lists sorted1={2,6,10,13,16,17,19}; sorted2={1,3,4,5,7,8,9,11,12,14,15,18,20}; of ...
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 ...
5
votes
3answers
4k views

Local max/min of Mathematica data sets

Is there a way in Mathematica to find the local maxima of a set of points? Suppose you have ...
22
votes
11answers
560 views

Using MapAt to map at a particular depth (levelspec)

I have the following sample list (my actual list is, of course, much longer): ...
12
votes
3answers
572 views

Simpler way to fill date gaps with zero values

One basic problem when working with data like sales and dates is the case where you dont't have sales in all days, so you have to fill it to take information as average or to make a plot. See this toy ...
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. ...
8
votes
2answers
1k views

Finding all partitions of a set

I'm looking for straightforward way to find all the partitions of a set. IntegerPartitions seems to provide a useful start. But then things get a bit complicated. ...
16
votes
1answer
4k views

How to remove redundant {} from a nested list of lists?

There are numerous examples here, whose end result is the removal of empty brackets {} and empty lists. I still can't find an example of simply removing redundant ...
12
votes
4answers
336 views

The gap between MapAt and ReplacePart for 2D data tables with headers

Consider a relational table derived from survey data, where each column ("001-01" ...) represents a responder and each row (...
8
votes
1answer
288 views

DeleteDuplicates[] does not work as expected on floating point values

Here is my simple example, and in this case function DeleteDuplicates does not work as expected. I want to FindRoot of my ...
7
votes
2answers
2k views

Get the coordinates from ContourPlot and RegionPlot

How do I get the coordinates from a contour plot I've done in Mathematica? For example, I have a two-variable function f[x, y], for which I can make a contour plot: ...
7
votes
4answers
514 views

Prepend 0 to sublists

My question is similar to this one, but my goal is to prepend a single 0 the each sublist, not incrementally many 0's. The file I'm working is a CSV containing around 50K sublists of length 35. I've ...
2
votes
4answers
717 views

List manipulation: position & max value combination

Starting with {{0, 0, 0}, {1, 1, 2}, {2, 3, 3}, {3, 4, 5}} I would like to get {{0, 2, 3, 5}, {1, 3, 2, 3}} where the ...
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 ...
14
votes
8answers
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? ...
6
votes
1answer
450 views

Finding all length-n words on an alphabet that have a specified number of each letter

For example, I might want to generate all length n=6 words on the alphabet {A, B, C} that have one ...
5
votes
5answers
638 views

Prevent Part[] from trying to extract parts of symbolic expressions

If you have a list, e.g. {1, 2, 3} then you can extract the $k$th part using Part (...
1
vote
3answers
1k views

How to create functions of arbitrary number of variables? [duplicate]

In the following code what would be the simplest way to generalize it to say some $N_f$ number of $z$ instead of just $z_1$ and $z_2$? ...
12
votes
2answers
1k views

How do I split up a curve into segments of equal length?

I have a curve that is defined as f[x] and what I'm attempting to do is to divide the curve into equal straight lengths for a number of segments of my choosing that I've defined as nSeg. I've created ...
12
votes
2answers
1k views

Simple algorithm to find cycles in edge list

I have the edge list of an undirected graph which consists of disjoint "cycles" only. Example: {{1, 2}, {2, 3}, {3, 4}, {4, 1}, {5, 6}, {6, 7}, {7, 5}} Each ...
8
votes
3answers
747 views

Checking for duplicates in sublists

I have a list with contains entries that are length 8 sublists,i.e. L1={{a1,b1,c1,d1,A1,B1,C1,D1},{a2,b2,c2,d2,A2,B2,C2,D2},...} and so on. Now, in my problem two ...
20
votes
5answers
758 views

MapThread over sublists of different length

I have a list which looks like this: l={{1,0,3,4},{0,2},{0,0,1,3},{1,2,0}}. Now I would like to count how many 0s the sublists contain in the first, second,... ...
17
votes
5answers
1k views

From a list to a list of rules

Starting from these two lists, var = {a, b, c} values = {{1, 2, 3}, {4, 5, 6}, {7, 8 , 9}} how can I generate a list of rules? ...
7
votes
3answers
1k views

Simulate MATLAB's meshgrid function

Here is MATLAB's meshgrid. I came up with these implementations in Mathematica: ...
7
votes
3answers
276 views

Numbering nested list according with Depth (or Level)

(This question is slightly similar with Sequentially numbering a nested list, but not exactly the same.) What I want Say I have a nested list ...
5
votes
2answers
549 views

Finding the intersection of two date lists

I've got two lists that look like this ...
17
votes
7answers
1k views

How do I check if any element in a list is positive?

As a simple example of what I would like to do, suppose I have a list a of all real numbers. I would like to perform a simple check to see if some element of ...
8
votes
4answers
504 views

Find list position and mapping list

Sorry, my English is not very good. I have two lists: ...
8
votes
2answers
166 views

Behavior of Inner depends on List dimensions?

Consider the following case: ...
6
votes
3answers
172 views

How to 'merge' a list like FromDigits, but with a mixture of numbers and symbols?

How do I go from {C,4,G,5,S,7} to C4G5S7
6
votes
5answers
440 views

Computing the equivalence classes of the symmetric transitive closure of a relation

I have a list of pairs, for example: ...
7
votes
3answers
224 views

How to Flatten Array of Arrays of the highest order in a simple way?

I have a matrix of matrices, given in the following code. I want to flatten the array... ...
6
votes
5answers
506 views

Elementwise join

I have two tensors of arbitrary but equal rank n (and equal dimensions): A and B, and I want to get a third tensor of rank n + ...
6
votes
4answers
293 views

How to sum over duplicates?

I have a list of the form: {{1, 0, 1}, {2, 1, 2}, {1, 0, 3}, {2, 4, 2}, {2, 1, -1}, {1, 0 ,0}} that I would like to sort such that I calculate the sum over the ...
6
votes
4answers
1k views

Alternatives to While Loops?

I am using Mathematica to run a probabilistic simulation. Essentially, I have a list of members of a population (they only have one, numerical, attribute, so it's just implemented as a list of ...
12
votes
5answers
588 views

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

This input: Permutations[Range[12]] Results in this (error) output: ...