Questions on the manipulation of List objects in Mathematica, and the functions used for these manipulations.
18
votes
11answers
643 views
Generating an ordered list of pairs of elements from ordered lists
I have a pair of ordered lists. I want to generate a new ordered list (using the same ordering) of length n by applying a binary operator to pairs of elements, one from each list, along with the index ...
2
votes
2answers
140 views
Comparing elements of the $n^{\text{th}}$ sublist in a ragged list with the $n^{\text{th}}$ member of a sequence
I have a list of lists that are not of the same length (for example, {{6}, {14}, {6, 26, 30}}), but I have to compare every element in the $n^{\text{th}}$ sublist ...
4
votes
1answer
128 views
MapThread with several cells as output
Assume I have defined the following function:
FF[{x_, y_}] := {x^2 + y^3, 3.5*x*y}
I would like to apply FF on a list of ...
16
votes
8answers
423 views
Applying And to lists of Booleans
I'd like to take {True,True,False} and {True,False,False} and apply And to get ...
1
vote
1answer
89 views
How can I manipulate with elements inside sublists if sublists of different lenght?
I have some kind of output like this: {{1, 5}, {1, 13}, {1, 5, 25}}. I would like to be able to enter in each sublist and make sums of every two elements in sublists, for example my desired output ...
3
votes
2answers
81 views
How to uncompress only the compressed elements in a matrix
I have data in a rectangular structure – something like matrix={{a,b,c},{d,e,f},{g,h,i}}. The problem is that some of the columns consist of uncompressed data and ...
5
votes
6answers
272 views
Creating sums of elements from a list
I have a list $(d_1, d_2, .. d_k)$ and I want to create all sums that I get for adding only two elements for my list $(d_1+d_2, d_1+d_3,...d_{k-1}+d_k)$. The ...
13
votes
7answers
318 views
Get the first element after the first sequence of length N of consecutively increasing values
I'm looking for an efficient way of extracting the first element after the first sequence of N consecutive elements in which the values are increasing.
If these are the data of a toy example:
...
5
votes
7answers
327 views
How to pick an element of a row corresponding to the minimum in a particular column?
How can I find what value in column 1 of my list corresponds to the minimum value in column 2?
3
votes
1answer
152 views
Efficiently keeping elements in a list (an input list) that exist in another list (a keep list)
I have some code that generates lists of integers (one such list is called, for example, inputList). I also have a "master list" of integers that should be kept, ...
1
vote
2answers
120 views
How to arrange a list on a triangular pattern?
I've made a multiplication table with this:
Then I removed the repeated permutations with:
gg = Range[1, 10]; Subsets[gg, {2}] // TableForm
Now, when the ...
10
votes
4answers
229 views
Thread a function over a list and with a non-atomic 2nd parameter?
From the documentation, Thread's behavior on functions where the first parameter is a List and the second is an atomic expression, is this:
...
1
vote
2answers
178 views
Symbolically associate vectors and their norms
I am wondering how to handle the following situation: I do have vectors of known dimension that I would like to handle symbolically. I suppose I can do something like
...
11
votes
2answers
318 views
Sorting a list with secondary criterion
Is there an easy way to sort a list on multiple levels of criteria?
By this I mean, first the list should be sorted according by criteria A (the same as using the usual sort function, ...
9
votes
5answers
247 views
Finding first instance of a relationship between elements in two lists
Suppose I have two lists, say:
A = {1,5,10,200,50,7}
B = {4,3,19,78}
For each element in A, I would like to find the index of the first element in B which ...
23
votes
12answers
816 views
Map a function across a list conditionally
It seems that this is a really basic question, and I feel that the answer should be obvious to me. However, I am not seeing. Can you please help me? Thanks.
Suppose I have a list of data ...
2
votes
1answer
163 views
Replace values which obey certain criteria
I'd like to replace all values in a list which obey one or more criteria with another value.
Example: Replace all values>30 by 30.
data={{3,35},{2,7}}
afterwards ...
18
votes
3answers
548 views
Emulating R data frame getters with UpValues
What's the best way to emulate R's data frames functionality? This includes the ability to select rows and columns in a 2-dimensional table by the string identifiers positioned typically in the first ...
2
votes
4answers
216 views
Building a list recursive with one or more arguments
Consider the following:
data={a,b,c,d};
res={{a,b,c,d},{b,c,d,e},{c,d,e,f},{d,e,f,g}};
The idea is to define a function ...
9
votes
5answers
674 views
Counting negative values in list
I would like to count the negative values of a list.
My approach was Count[data, -_] which doesn't work.
How can I tell Mathematica to count all numbers with ...
7
votes
2answers
271 views
find subsequences of constant increase
A list like
l = {0, 1, 2, 3, 4, 5, 7, 9, 12, 13, 18, 19}
may have subsequences of constant increase, $a_{n+1} = a_n + k$.
For example:
...
9
votes
1answer
160 views
Map efficiently over duplicates in list
I am interested in mapping a function, f over a (long) list which contains duplicates.
Since this function takes a while to evaluate I would like to make use of ...
7
votes
3answers
241 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 ...
3
votes
4answers
152 views
Building intervals
I'm facing the right know the problem of building intervals to an arbitrary number. The special thing is that the first and the last intervals should have fixed length, while the "middle" ones should ...
1
vote
2answers
118 views
Using patterns in ReplaceAll to extract elements from tuples at arbitrary depths
Please consider the following:
I need to extract from MyList all last parts of each 3-tuple.
...
4
votes
2answers
207 views
Simpler way to repeat an execution with 2D points?
q has the coordinates of quadrilateral. I can get the output below with brute-force but I want to find a simpler solution, perhaps something like f<-q[[1;;2]].
...
1
vote
1answer
162 views
How can I permute a multiset?
I have a multiset {1, 3, 3, 1, 2} and would like to randomly permute the classes like so: {2, 1, 1, 2, 3} or {3, 2, 2, 3, 1}, what is the simplest and most efficient way to do this?
In reality the ...
7
votes
1answer
251 views
Very fast way to do a coordinate frame transform
I need a function that rotates and translates a huge amount of line segments.
For example, I have a set of line segments in the form {{x0,y0,z0},{x1,y1,z1}}
...
3
votes
2answers
168 views
Creating a Nearest function programmatically
I've been trying to work out how to create a Nearest function programmatically. My goal is to produce something similar to this, a hand-assembled function:
...
-5
votes
3answers
260 views
Constructing lists by applying functions to another list
Suppose f is a function of two variables: $f = f(x,y)\quad$ and $L$ is a list. Could someone help me in defining a list of the form:
$D = \{f(x,y)\ |\ x \in L,\ y \in L\}$
I tried this:
...
12
votes
4answers
234 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
2answers
128 views
3
votes
1answer
139 views
splitting a list into files
Given is a list with x, y, z coordinates:
{{100, 94, -1.112}, {100.05, 94, -1.112}, {100.1, 94, -0.982}, ...,
{100, 94.25, -1.112}, {100.05, 94.25, -0.855}, {100.1, 94.25, -0.728},
..., ...
10
votes
3answers
267 views
Generating Linear Extensions of a Partial Order
Given a set $S$ and a partial order $\prec$ over $S$, I'm looking for a way to "efficiently" generate a list of linear extensions of $\prec$. Suppose the partial order is given by a ...
5
votes
2answers
134 views
Creating a list of PopupMenus that dynamically update an element in a list
So as the title says I am trying to make a list where each element is determined by a users choice of an element in a PopupMenu.
My first attempt:
...
1
vote
1answer
334 views
Fastest way to sum pairwise potentials
I've been writing a function to sum a pairwise potential on two lists, i.e. two charged bodies, each containing N >> 1 and ...
14
votes
5answers
417 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,... ...
12
votes
2answers
431 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 ...
3
votes
2answers
189 views
Using the elements of a subset in a Do loop
I would like to use the elements of Subsets in a Do loop.
I have:
...
3
votes
3answers
177 views
Incrementing a nested list element
I've been wanting to increment a nested list element of which I know the "coordinates". I thought of the following procedure, using Apply with Part.
...
6
votes
3answers
273 views
Specifying string patterns in DeleteCases
It seems that DeleteCases is not compatible with string patterns, at least directly (see, for example, this question). Is this true? If so, why is this the case? ...
4
votes
2answers
195 views
Access pairs of vectors, rather than the matrices, in partitioned data structure at a levelspec
I have some old code to analyze correlation between 2 time series by looking at windows of different lengths shifting across the time series data. The code:
gets 2 sets of time series data (in ...
4
votes
3answers
171 views
position of sequence of elements in list [duplicate]
Possible Duplicate:
Finding a subsequence in a list
Question
The position of {3, 5} is the list
{1, 3, 4, 3, 5, 5, 1}
is 3. How can such a position ...
0
votes
1answer
69 views
Need help to finish this prime signature function?
I'm trying to create a prime signature for line segments.
...
3
votes
5answers
528 views
Dealing with Empty Brackets in a List
I have a large list with varying constituent parts. Some of these are like this:
i.e. graphlist[[34]]
...
7
votes
1answer
147 views
Built in way to de-list singletons?
Is there a built in method to de-list singleton expressions, like this rule-based solution:
expr_ :> If[Length[expr] == 1, First@expr, expr]
In data ...
10
votes
6answers
558 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 ...
0
votes
2answers
280 views
How to generate table without comma and bracket or get rid of those?
I want just data without comma and brackets. Even TableForm is not working for me.
For example, the general pattern of my table is
...
3
votes
5answers
221 views
How to extract strings from the list with an additional condition on previous elements?
There are a long list of strings $s$ and two lists of substrings $s1$ and $s2$. I want to take all elements of $s$ which contain a substring from $s2$ and such that before it on no more than $n$ ...
2
votes
3answers
117 views
Function[] argument nesting for operations like Select[]
The following code selects a special element from a list
thelist = {"this", "notthis"};
Select[thelist, (# == "this") &]
What I want is a function which ...




