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

learn more… | top users | synonyms (3)

14
votes
3answers
421 views

Quick multiple selections from a list

What is the fastest way to make multiple selections from a list? Compiled methods included. For example, here are two methods for selecting a subset, compared:- ...
7
votes
3answers
2k views

Simulate MATLAB's meshgrid function

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

Equating matrices (or higher order tensors) element-wise

Say I have two matrices (or, as in my case, higher order tensors) $A,B$, and I want to solve the equation $A=B$. To do so , I need a list of equations that equate entry-wise the elements of $A$ and ...
7
votes
2answers
302 views

Intersection for lists of numeric data

I know that Intersection is a pattern matching function and will not evaluate list elements to determine if two or more list have equal elements. So my question is, ...
7
votes
3answers
293 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 ...
11
votes
3answers
680 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? ...
8
votes
2answers
169 views

Behavior of Inner depends on List dimensions?

Consider the following case: ...
5
votes
2answers
586 views

Finding the intersection of two date lists

I've got two lists that look like this ...
12
votes
2answers
670 views

Filtering and Replacing outliers

I have a set of data that measurements of temperature vs time (date). It is easy to realize when the sensor went wrong as one might see a blip on the data. How to teach to Mathematica to: 1) Detect ...
10
votes
6answers
325 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
4answers
545 views

Find list position and mapping list

Sorry, my English is not very good. I have two lists: ...
16
votes
7answers
733 views

How to use Union on list of lists without sorting them first?

If I do ClearAll[a, d] lsts = {{a, d}, {a, d}}; Union[lsts] I get the expected answer {{a, d}} but if I do ...
11
votes
3answers
612 views

Delete duplicates in a list, depending on the sequence of numbers

Below, list is a representative sample of my list, which contains lists of integers. I would like to be able to input: ...
7
votes
3answers
236 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
329 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
2answers
479 views

Map a function over the columns of an M x N array

I have a $N \times M$ list of lists, or rather, a list of records and I want to map a function over its columns (e.g. find the mean temperature, age, etc.). Map ...
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 ...
5
votes
3answers
606 views

Replace very small numbers by zero in the output of a list

I have a long nested list, but many elements are numbers of order 10^-18 or less, eg ...
7
votes
2answers
264 views

Threading behavior of SameQ vs Equals

I ran into a bug in my code today based on an errant assumption. Namely, I thought that: ...
6
votes
2answers
791 views

How can I get every distinct size-n combination of a list?

Let's say I have a list: {a, b, c} I would like to, for say $n=2$ get every distinct pair from that list. That is, the expected result should be, for some ...
5
votes
1answer
353 views

DeleteCases messing with my mind

I'm losing my mind. Please tell me my laptop is doing weird things and not me. Or do I need to get committed someplace? ...
3
votes
2answers
987 views

Function returning Null along with other unexpected expressions

When I use some function, at the end along with the output I get some NULLs returned that I don't understand the reason for and are highly undesirable. For example, when I define the reversal of list ...
3
votes
2answers
574 views

hexList[[1]] returns a list of decimal numbers

Sorry for not being clear about this question earlier. I appreciate the answers I got, but the edits I made should make the question more understandable. I have been working with hex in ...
2
votes
3answers
325 views

Re-arranging / selecting of a data table very slow in For loop [duplicate]

My task is quite simple; I have a table of data like M = {{1,2}, {1,3}, {3,4}, {5,1}, {6,9}, {6,8}, {6,1}}; so the table is sorted with respect to the first ...
22
votes
4answers
5k views

Finding Local Minima / Maxima in Noisy Data

I'm trying to find local minima / maxima in noisy data, consisting of data values taken at certain time intervals. Ideally, the function should take a pair of lists (one containing time values and one ...
14
votes
10answers
1k views

Pretty way to group elements at odd and even positions

How to make a function that splits list elements by odd and even positions? Shortest implementation wins. I myself came up with: ...
14
votes
9answers
493 views

Distributing elements across a list of lists

I have two lists: u = {{1, 3}, {2, 6}, {3, 9}} v = {0, 4} and I want to obtain this list from them: ...
14
votes
8answers
875 views

DeleteCases on list of Strings

Consider the following: data={"AB","CD","AF"}; Now I would like to delete all String from data which starts with "A". ...
13
votes
6answers
1k 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 ...
8
votes
1answer
171 views

Quickly selecting for points in a set that are within a critical distance of points in another set

Imagine two lists of two-dimensional coordinates: listA = RandomReal[{0,100},{202,2}]; listB = RandomReal[{0,100},{97,2}]; I'm attempting to quickly generate a ...
16
votes
2answers
3k views

Is there an equivalent to MATLAB's linspace? [duplicate]

Does Mathematica have an equivalent to Matlab's linspace? I want to make a list with "start", "stop" and "number of points". What is the neatest way of doing this?
15
votes
7answers
8k views

Mathematica: finding min/max in list

I have a list of coordinates like this one: {{x1,y1},{x2,y2},{x3,y3},...,{xn,yn}} I need to get the minimum and the maximum of all x-values and the minimum and ...
14
votes
4answers
950 views

Constructing a list that includes a leading zero (01,02,03 … 55, 56, etc.)

I am constructing a list for use in file operations. Say I want to create list which contains values from 01 to 87. The kicker is that the first nine integers need ...
18
votes
11answers
1k 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 ...
17
votes
6answers
613 views

How do I replace a missing value in a column with the value immediately above throughout a table?

I have a large table (7000 rows × 17 columns) of terse textual data. In many of the columns, empty entries have been replaced with "." as a marker. Working from the top of the columns downward, I want ...
14
votes
6answers
1k views

Shuffle product of two lists

I want to do the following: I have two lists {a_1,...a_n}, {b_1,...,b_n} and I would like to build now all shuffles out of this. This means all unions of these ...
11
votes
3answers
526 views

How to add lists with unequal length?

Given lists of unequal lengths, I want to add them together element-wise, treating missing elements as zero. For example, {1, 2, 3} + {a, b} + {x} should give ...
10
votes
1answer
256 views

Drop selection of columns from a ragged array

I have an application where I need to drop some arbitrary list of columns from a ragged array (where of course the shortest array rows have at least all the specified columns). E.g., given a ragged ...
10
votes
4answers
650 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: ...
9
votes
4answers
948 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 ...
7
votes
4answers
763 views

How make f[{x,y}] evaluate as f[x,y]? [duplicate]

I frequently encounter the situation where I have a function of two real variables defined, e.g.: f[x_, y_] := 9 - x^2 - y^2 But then I need to feed into ...
7
votes
2answers
949 views

Elegant way to handle columns operations

Inspired by this question from @sjdh and by my recurrent use of columns operations in database sets, I was looking for one way to make columns operations more symetric, so I can handle with matrix and ...
17
votes
6answers
846 views

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

The usual Partition[] function is a very handy little thing: ...
11
votes
5answers
1k views

How can I simulate this animation of checking for prime numbers?

I can only implement a very simple one, I want to make my code look like that. Any better ideas? ...
11
votes
7answers
747 views

How can I Flatten this List with Inner List of Lists?

Given the following List ...
10
votes
3answers
333 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: ...
9
votes
5answers
3k 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 ...
6
votes
2answers
2k views

Is it possible to compute trapezoidal rule numerical integration?

Is it possible to compute trapezoidal rule numerical integration? I know that Mathematica has Interpolation, and that a list of points can be interpolated and then ...
5
votes
3answers
592 views

Combining two lists of different dimensions into a list of all combinations of points?

I have two ranges of values, one from 0 to 20 and the other from 0 to ...
21
votes
3answers
477 views

Is there a bug in Pick?

I wanted to use the Pick function with a condition. But there seems to be an issue here. Take a look at this: ...