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

learn more… | top users | synonyms (3)

9
votes
8answers
311 views

Fast way to get positions of “boxed” array elements?

Given a 2D array (arbitrary numeric / evaluates to numeric elements, simplified for examples, and can be arbitrary dimensions so long as the operation makes sense, I'm working with 2K X 2K in my ...
9
votes
6answers
258 views

Using MapIndexed only at certain elements of a list

MapIndexed is a very handy built-in function. Suppose that I have the following list, called list: ...
9
votes
5answers
300 views

Count consecutive occurrences in a list above a certain value

I am trying to tally and sort the number of consecutive occurrences in a list above a certain value. For instance: ...
9
votes
6answers
390 views

Performing Computations on Sets

I would like to find a permutation of $\quad S=\{\frac{1}{10}, \frac{1}{2}, \frac{4}{7}, \frac{3}{5}, \frac{2}{3} \}\quad$ that maximizes the sum of theses elements raised to unique powers: ...
9
votes
5answers
409 views

Fast way of finding position of Interval containing an Integer

I have a large list (about 2.2 million) of pairs of integers. Each pair defines an Interval[{}]. Given some integer x, I need to ...
9
votes
5answers
231 views

Fill out blanks with a upcoming number in a list?

I have a bunch of arrays looking like this: {"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ...
9
votes
5answers
301 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 ...
9
votes
3answers
369 views

What is the most efficient way to map a linked list?

In order to work with lists effectively using common recursive patterns from functional programming, it's often most convenient to worked with the "linked list" representation, that looks like this: ...
9
votes
4answers
244 views

How to pass a list of arguments into HoldAll

I have a list of arguments (which in reality is lengthy): arguments = {a, b, c} arguments2 = {a_, b_, c_} f[Sequence@@arguments2] := a + b + c Note: It seems ...
9
votes
5answers
202 views

Is there a better way to add a “key” for the list of GatherBy?

In ruby , 1.upto(10).to_a.group_by{|x| x%3} gives {1=>[1, 4, 7, 10], 2=>[2, 5, 8], 0=>[3, 6, 9]} I would like use ...
9
votes
2answers
180 views

How to find synchronization offset?

I have 2 sets of data containing delays (audio / video). ...
9
votes
2answers
398 views

How to represent a list as a cycle

I want to select distinct cycles (represented by List). The cycle {a, b, c, d} must be the same as {b, c, d, a} or ...
9
votes
4answers
586 views

Passing large list by reference

I have the following problem: I would like to control evaluation of a variable that points to a list. For example, frequently in the code I have functions of the form that are supposed to work on ...
9
votes
4answers
253 views

MapThread with non-rectangular lists

MapThread works fine and dandy with rectangular list structures: MapThread[f, {{{a, b}, {c, d}}, {{1, 2}, {3, 4}}}, 2] ...
9
votes
4answers
381 views

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

This input: Permutations[Range[12]] Results in this (error) output: ...
9
votes
2answers
414 views

Rearranging a List

I am trying to rearrange/sort a list i.e. {{1,2},{10,140},{43,10},{1,140},{43,2}} into ...
9
votes
2answers
239 views

Combining nested lists that meet certain criteria for a permutation

I have the following list representing a permutation on 26 characters: ...
9
votes
2answers
2k views

How to get Matlab data imported with the same dimensions?

I have some Matlab image data with the following dimensions (output is from Matlab): >> size(im) ans = 86 86 3 45 The data imports just fine ...
9
votes
1answer
181 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 ...
9
votes
1answer
184 views

Unexpected result from Flatten

Consider the following three evaluations involving Flatten: Flatten[f[f[f[x, y], 1, 2], f[x, y]], Infinity, f] f[x, y, 1, ...
9
votes
2answers
278 views

Speed up 4D matrix/array generation

I have to fill a 4D array, whose entries are $\mathrm{sinc}\left[j(a-b)^2+j(c-d)^2-\phi\right]$ for a fixed value of $\phi$ (normally -15) and a fixed value of $j$ (normally about 0.00005). The way ...
9
votes
1answer
190 views

Creating a number based on given conditions

In the grade 7 math curriculum here in Alberta we teach divisibility. I'm trying to write a program to create questions based on the idea of a student being given say, 4 digits, and then choosing ...
9
votes
1answer
173 views

Ranking Function Allowing for Ties

I have a list that I need to be able to assign ranks to individual elements in, giving it a number related to its position if the list were to be sorted, allowing for ties. For example, ...
9
votes
2answers
217 views

How to partition a list and leave in the last sublist which is of different length? [duplicate]

How to partition a list and leave in the last sublist which is of different length? In[75]:= Partition[{1,2,3,4,5},2] Out[75]= {{1,2},{3,4}} I want it to be ...
9
votes
2answers
536 views

Flatten at a certain level

In an earlier question the brainteasing fourth syntax variant of Flatten was discussed. I see that with ...
9
votes
1answer
260 views

Efficient way to solve equal sums $x_1^k+x_2^k+\dots+x_5^k=y_1^k+y_2^k+\dots+y_5^k$ with Mathematica?

I need to solve the system of equations, call it $S_1$, in the integers $$x_1x_2x_3x_4x_5 = y_1y_2y_3y_4y_5$$ $$x_1^k+x_2^k+\dots+x_5^k=y_1^k+y_2^k+\dots+y_5^k,\;\; k= 2,4,6$$ I used a very ...
8
votes
10answers
332 views
8
votes
7answers
612 views

How to partition a list in a specific way

I have a list: a = {{1, 2, 3, 4, 1, 2, 3, 4}, {5, 6, 7, 8, 5, 6, 7, 8}}; Using Partition and ...
8
votes
5answers
345 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. ...
8
votes
4answers
536 views

Find positions of items in a list based on neighbours

How can I select items from a list where the selection criterion depends on the neighbouring items? For example select all indices where a change has occurred with respect to the previous element in ...
8
votes
4answers
261 views

Searching linked lists that contain lists?

Following the advice I've read here and other sites, I've been trying to use the Mathematica equivalent of a linked lists... ...
8
votes
4answers
2k views

What is the cleanest way to prevent divide-by-zero warnings?

If I evaluate {1, 2, 3, 4}/{5, 6, 0, 8}, obviously I get one warning: ...
8
votes
3answers
479 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 ...
8
votes
8answers
310 views

How to use Map inside MapThread?

Given this input lst1 = {{a, b, c}, {d, e, f}}; lst2 = {1, 2}; and the goal is to generate this output ...
8
votes
5answers
1k views

How to create a list of pairs from 1d list(s)?

Say I've got two 1-dimensional lists A = {1,2,3} B = {a,b,c} How do I create a list of all pairs from list A such that the ...
8
votes
5answers
282 views

Take both of the diagonals through an element in a matrix

I have a matrix like this: Reverse@Array[List, {8, 8}] // MatrixForm I need a function that given an element of this matrix will return all the elements ...
8
votes
3answers
496 views

How to rebuild original data from a histogram?

I have data in the following form. I have a list of values and a list of frequencies that indicate how often each value has occurred. Example list of values: ...
8
votes
3answers
476 views

Creating a simple function to compute the average of the difference between pairs of elements in an array

I have a list of the form: {{{1, 2}, {3, 4}}, {{5, 6}, {7, 8}}, {{9, 10}, {11, 12}}} How can I create a function which will take each set at the highest level of ...
8
votes
4answers
358 views

Partitioning a list by recursion (Programming Paradigms via Mathematica (A First Course))

I am working through the course Programming Paradigms via Mathematica. One of the homework exercises for the section Recursion I: Passing the Buck is as follows: Use recursion to partition a ...
8
votes
5answers
289 views

Span a function across several consecutive elements in a list

Suppose that I have a list called list. I would like to span an arbitrary function f across specified consecutive elements in ...
8
votes
6answers
203 views

Custom Matrix product

I have a list: list1 = {{{a1, a2, a3}, {b1, b2, b3}}, {{c1, c2, c3}, {d1, d2, d3}}}; I want an operation that gives me: Is there a built-in way of doing ...
8
votes
2answers
321 views

Retrieving duplicates from nested list

Consider the following: data={{1,a},{10,a},{5,b},{4,c}}; In my case duplicates are defined when for {x1,y1} and ...
8
votes
1answer
300 views

How can I collect data for visualization of quick sort?

I know how to implement quick sort in Mathematica. But I don't know how to get the temp data for visualization, because I used recursion. I want the effect like this. ...
8
votes
4answers
279 views

Gather list elements by index

The following list has some elements that are labeled. For example {1, 2} -> 1, {-1, 3} -> 3, etc: ...
8
votes
5answers
250 views

Wrapping a function in count

I am working through the Programming Paradigms via Mathematica (A First Course) and am attempting to answer the following: Use recursion to count how many times the argument can have its square ...
8
votes
3answers
183 views

Select and Blank

I try to filter sublists of a list which match a pattern. test = {{"String1", "a"}, {"String2", "b"}, {"String3", "a"}, {"String4", "a"}}; The result should ...
8
votes
4answers
252 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 ...
8
votes
5answers
196 views

Refer to next element of list when iterating using Map [duplicate]

Is it possible to refer to the next element of the list when I'm using Map or should I always use For in this case? For example ...
8
votes
4answers
136 views

Mark selected sub-lists in the list they were selected from

I've got this simple problem with two lists. I select some items from a list, but I want to visualize the difference between the previous list and the list that I create with ...
8
votes
5answers
296 views

How can I find these patterns' signatures?

I think I can explain it best starting with an example. I have the following lists: ...