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

learn more… | top users | synonyms (5)

11
votes
1answer
431 views

How to merge Datasets representing matrices with named rows/columns?

I am working with square (non-symmetric) matrices with named rows and columns. The data I receive is sometimes messy and rows/columns may come in various permutations. I usually need to ...
10
votes
8answers
836 views

Best way to emulate MATLAB's bsxfun using Map and similar functions

Given a matrix, we want to subtract the mean of each column, from all entries in that column. So given this matrix: ...
10
votes
8answers
1k views

Position of First nonzero number

I want to know is there any one line code to find position of first nonzero number without calculating position of all non zero numbers. For example, ...
10
votes
9answers
654 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? ...
10
votes
6answers
495 views

Unique Element in List

I have a list a, and want to find out whether there is a unique element in the list. For instance a={x,y,z,y,x} has an unique ...
10
votes
6answers
670 views

Flatten nested lists

I have a list as follows lis= {a, {{{b}, {c,d,e}}, {{f}, {g,h,i}}}} which I would like to flatten to ...
10
votes
8answers
622 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 ...
10
votes
10answers
682 views

Matrix indexed by one number

I'm trying to find a generic way (for arbitrary dimensions) to create a matrix like so a[1] a[2] a[3] a[4] i.e where it is indexed by one number, instead of say ...
10
votes
4answers
307 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... ...
10
votes
4answers
2k 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) ...
10
votes
5answers
647 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 ...
10
votes
4answers
771 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: ...
10
votes
6answers
577 views
10
votes
5answers
619 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 ...
10
votes
5answers
593 views

How to find first list element that differs from average of N previous elements by more than a given amount?

Given a list of real numbers, I need to write a function that returns the value of the first element in the list that differs from the mean of the previous $N$ elements by greater than $P$ standard ...
10
votes
7answers
263 views

Extract left-upper triangular data from a square matrix-form list

Hopefully, this question is not too basic or obscure. I'd like an idea on how to extract this {{1}, {5, 2}, {9, 6, 3}, {13, 10, 7, 4}} from ...
10
votes
4answers
345 views

Element-wise test on List elements

This question could sound pretty silly but I can't find a way to apply element -wise tests to a list. For example if I digit ...
10
votes
5answers
954 views

How to subtract one list from another, treating each elements as distinct, assuming the smaller list is a subset of the larger list? [duplicate]

Suppose that I have two lists of different sizes, the smaller of which is a subset of the larger, e.g. a = {"A", "A", "A", "B", "B", "C"} b = {"A", "B"} How can ...
10
votes
3answers
916 views

Count consecutive positions with the same value

I want to program a function that counts the successive positions with the same value: In[]= ConsecutiveValues[{1, 1, 1, 1, 2, 2, 1, 0}] Out[]= {4, 2, 1, 1} In ...
10
votes
5answers
438 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 ...
10
votes
4answers
329 views

Efficient way to make subsets of list with placeholders

I have an arbitrary list of unique elements: lst = {a, b, c, d} Documentation allows finding subsets with same number of elements, say ...
10
votes
4answers
201 views

Timing problem with ReplaceRepeated

I have the following data: ...
10
votes
8answers
426 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 ...
10
votes
3answers
417 views

Modifying strings in a list efficiently

I have a list of strings $\{s_1,s_2,\ldots,s_n\}$. I would like to to produce the following list of strings: $$ \{s_1<>1,\ 1<>s_2<>1,\ldots,\ 1<>s_n\} $$ In other words, I want ...
10
votes
5answers
328 views

Split according to List and apply rule

I have a list which looks some thing like this {a1, a2, a3, a4, a5, a6, a7, a8, a9, a10} Now I want to split it according to lengths ...
10
votes
5answers
438 views

How to randomly select subsets

I have a list of around 300 elements. I want to sample subsets of length 25 such that my samples are all distinct. My first inclination was to use something like ...
10
votes
4answers
387 views

Complement of multisets

Given lists $a$ and $b$, which represent multisets, how can I compute the complement $a\setminus b$? I'd like to construct a function xunion that returns the ...
10
votes
5answers
649 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: ...
10
votes
3answers
910 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 ...
10
votes
3answers
210 views

Pick with nested list

I have a list of pairs of values. Some of those pairs are invalid based on another list. I would like to select only the valid pairs. ...
10
votes
2answers
342 views

Using Gather to rearrange my data

I have a list of elements: {{1, 2}, {1, 5}, {2, 6}, {3, 7}, {4, 8}, {5, 6}, {5, 9}, {9, 13}, {10,11}, {11, 12}, {11, 15}, {15, 16}} I have to divide it into ...
10
votes
4answers
268 views

Convert elements of list to string

how easily can I convert elements of this list to string. If I have output like this: {{M, 1, 0, 0, 1, 1, 1, 0}, {A, 0, 0, 0}} And I want something like this: ...
10
votes
4answers
267 views

How to make FlattenAt work with Span?

This works: MapAt[h, {a, {b, c}, {d, e}, {f}}, 2 ;; 3] (* {a, h[{b, c}], h[{d, e}], {f}} *) but this doesn't: ...
10
votes
4answers
336 views

How to take and evaluate a specific part of a list without evaluating the rest?

I have a large list, for example, lis = {x + y, x y, Sin[x] y + Exp[y], x^2 y} and its elements depend on variables x and ...
10
votes
5answers
532 views

ListPlot under conditions

I have a data file containing several columns and thousands lines of data. Below I present a small portion of it, in order to express my issue: ...
10
votes
2answers
4k 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 ...
10
votes
3answers
905 views

Splitting a list at a particular position

Is it possible to split a list into two lists at a specific position? The main list is for example: data={{xa,ya},{xb,yb},{xc,yc},...,{xz,yz}}. I want to split ...
10
votes
6answers
591 views

The longest run of at most k different elements in a list

I have a long list with ca. 500K elements. The list contains about 10K different elements. For simplicity let’s assume the list is of the following form: ...
10
votes
3answers
418 views

How to “ignore” an element of Map or MapIndexed

Say I have some function that I'm applying every element in a list to... if that element matches some criteria: ...
10
votes
3answers
208 views

Association Subtotals with Lists as Keys

I have the following Association: ...
10
votes
4answers
507 views

Building a tree

Given a list of word characters, such as this one, I'd like to build a tree, similar to this makeTree function, but with the tree in a different format. So, for an input such as ...
10
votes
4answers
872 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 ...
10
votes
2answers
582 views

Faster “stuttering” accumulate?

Given some list of arbitrary precision numbers, e.g. (actual lists are 1M+ elements long): test={0, 2, 2, 47839283, 2, 0, 0, 2, 0, 1, 2, 0} I need to accumulate ...
10
votes
2answers
483 views

Select cases from a list

I have a list in the form : {1,1,1,0,-1,-1,1,1,1,0,0,0,0,-1,-1} No I'm trying to select only those sequences which start with 1 have a zero (or many zeros) ...
10
votes
4answers
1k 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 ...
10
votes
2answers
681 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 ...
10
votes
3answers
609 views

Zero-dimensional matrices

In a recent Mathematica project, $(n \times 0)$- and $(0 \times n)$-dimensional matrices have suddenly become a frustratingly common edge case for me. For instance, consider the following two ...
10
votes
5answers
667 views

Best way to modify values in a list of rules?

Recently I had to solve a problem similar to this: Let's say I have a list of list of rules ...
10
votes
2answers
491 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 ...
10
votes
2answers
2k views

Estimating the full width half maximum of a peak

I have a dataset of which I'm attempting to determine the full width at half maximum. A picture of the data is given below, and the dataset itself can be found here (pastebin). Now, this set has a ...