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

learn more… | top users | synonyms (5)

12
votes
2answers
210 views

why MeanFilter is nearly 100 times slower than MovingAverage for 1D array?

I used to average over my data with MeanFilter before I learn about MovingAverage and thought that these two functions are similar except that MeanFilter is more powerful for its ability to deal with ...
12
votes
4answers
410 views

Equivalent Nested Loop Structure

Consider the following examples: ...
12
votes
1answer
283 views

Mapping on leaves

Say I have some nested structure, such as {a,{{b,c},d,{e,{f,g}}}}, and I want to apply a function $q$ to each of the leaves; that is, I want the output to be ...
12
votes
3answers
1k views

How can I remove the singleton dimensions of an array? [duplicate]

If I have an array A, for which Dimensions[A] is {9, 9, 1, 1, 3, 4}, how can I convert ...
12
votes
2answers
305 views

Efficient conversion between two partition representations

I have a list of distinct expressions. We can represent a partitioning of list in two ways: As a list of sublists ...
12
votes
3answers
577 views

Riffle and Partition

At some point I noticed that I was using Riffle and Partition together a lot. I would do things like ...
12
votes
3answers
898 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
2answers
236 views

Unexpected behavior of Sequence — using Sequence to delete parts of an expression

I thought that assigning Sequence[] to the part of an expression was an effective way to remove it. For example, the following code yields {2,3,4,5}: ...
12
votes
2answers
1k 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 ...
12
votes
1answer
836 views

How to extract and replace submatrix of a doubly-periodic matrix?

How can I effectively extract and replace a rectangular subpart of a toroidal matrix, i.e. one where boundaries are connected at opposite ends? Since the submatrix can overhang the edges, a simple <...
12
votes
1answer
193 views

ListConvolve Memory Hemorrhage

Bug introduced in 10.0.0 and fixed in 10.2.0. I wrote a routine that convolves an impulse response array with a test array and checks for the RMS difference between that convolution and a data ...
12
votes
0answers
237 views

Strategies to find curves on messy data using FindCurvePath

I have a set of data points that correspond to roots of a transcendental equation with respect to a parameter (the abscissa) which, by the properties of the system, define continuous curves (might be ...
11
votes
10answers
692 views

Elegant way to map a function to only the last element of each sublist [duplicate]

Suppose that I have the following list, called test: test = {{{a1}, {a2, a3}}, {{b1}, {b2, b3}}, {{c1}, {c2, c3}}}; Now ...
11
votes
6answers
2k views

Multiplying two dimensional data by a constant

I have a list of lists of the form: {{1, 2}, {2, 4}, {2, 8}} But I want to multiply only the second dimension of that data by a constant. I know I could do this ...
11
votes
11answers
487 views

Replace elements in list not matching elements of another list at the same position

I would like to compare two arrays: m = {a,b,c,d,d,f}; n = {b,b,a,d,d,e}; and get: {0,b,0,d,d,0} I have tried all kinds ...
11
votes
4answers
6k views

How can I multiply matrix and vector element wise like Numpy?

I have an $M \times K$ matrix $C$ and a length $K$ vector $v$. I want to form the $M \times K$ matrix $S$ where $s_{ij} = C_{ij}/v_j$. To do this in numpy I simply divide the two objects like this <...
11
votes
4answers
4k 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: ...
11
votes
4answers
641 views

In a list of points, how to efficiently delete points which are close to other points?

Consider a list of points: pts = Partition[RandomReal[1, 10000], 2]; ListPlot[pts] I'd like to delete points so that the minimum distance between two points is ...
11
votes
5answers
3k views

How to find rows that have maximum value?

Suppose if I have following list { {10,b,30}, {100,a,40}, {1000,b,10}, {1000,b,70}, {100,b,20}, {10,b,70} } How to find rows that have max value in ...
11
votes
10answers
841 views

Finding neighbors from list

Say you are given the following list: list={{3, 2, 1}, {3, 4, 2}, {2, 4, 1}, {1, 4, 3}}; Two numbers $x,y$, not necessarily distinct, are neighbors if one of the ...
11
votes
4answers
486 views

How do I extract a matrix of only positive numbers given a set of assumptions?

I want to divide a matrix: mat = {{a, 0, -b}, {d, a, 0}, {0, 0, -a}} with the following assumptions: ...
11
votes
7answers
255 views

DateList coupled with String Operations

Through some webscraping, I have the following list: ...
11
votes
4answers
410 views

What's fastest way of defining 10^5 down values?

I want to define isGood[___] = False; isGood[#] = True & /@ list where list is a list of several million integers. ...
11
votes
3answers
363 views

What is the best way to flatten a linked list with lists as values?

By following the advice on this site I have ended up with a linked list like the following: acc = {{1, 2}, {{2, 3}, {{3, 4}, {{4, 5}, {{5, 6}, {}}}}}}; This was ...
11
votes
3answers
370 views

get position index for all element in a list

For example mat={{a,b},{c,a,a}} How to write a function posindex that posindex[mat] will ...
11
votes
5answers
427 views

Most efficient way of making pair list from a list

I have a bunch of datasets which looks like: 3 7 1 6 5 8 2 4 1 2 8 1 5 2 5 ... and I need to make a list of pairs such that the first element makes a pair with ...
11
votes
3answers
324 views

Gathering of list

Problem statement The following challenge was recently posted to the J language programming forum by Skip Cave (http://jsoftware.com/pipermail/programming/2016-March/044561.html): "The animal ...
11
votes
2answers
225 views

How to make a Slash header in Grid?

Here is an example, ...
11
votes
5answers
451 views

How to sort list of mixed types of elements with each type a specified canonical order?

For example, here is a list {{1, "u"}, {6, "d"}, {3, "u"}, {4, "d"}, {2, "u"}, {5, "u"}, {3, "d"}, {1, "d"}, {4, "u"}, {2, "d"}, {5, "d"}, {6, "u"}} The ...
11
votes
6answers
390 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: ...
11
votes
6answers
461 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: $\;\{0,1,2,...
11
votes
5answers
2k views

Ways to compute inner products of tensors

One way to evaluate the following sums is combining Table and Sum: $u_{abcd} = \sum_{e=1}^3 v_{aeb}w_{ced}$ $q_{ab} = \sum_{d,e=1}^3 v_{d e a}w_{deb}$ It will look like ...
11
votes
5answers
370 views

Partition a list into sublists of different lengths

I have the list {a, b, c, d, e, f, g, h, i} and I want to make a sub-list of the form {{{a, b}, c}, {{d, e}, f}, {{g, h}, i}} I'...
11
votes
5answers
590 views

Graphically approximating the area under a curve as a sum of rectangular regions

I am completely new to Mathematica. Basically I was trying to write a code to plot a function and draw the approximate area by rectangles. To be more precise, plot a function ...
11
votes
3answers
421 views

Looking for an elegant way to construct this tensor-product-ish list

I would like to make the following matrix: ...
11
votes
6answers
374 views

Fill out blanks with a upcoming number in a list?

I have a bunch of arrays looking like this: {"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ...
11
votes
3answers
522 views

How do you concatenate matrices? And how do you make block matrices?

This is pretty trivial to do in Matlab, but I have not seen a function for it in Mathematica. Here is how you can do it with Join and ...
11
votes
3answers
216 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. ...
11
votes
9answers
769 views

Forming an upper triangular matrix from the elements of a list

I asked this question before, but i was closed because it the question was not comprehensible enough. So i reworded it, hope that's ok. I have a list with 6 elements. ...
11
votes
3answers
320 views

Partition a list based on specific elements? Grab the sublists beginning with a certain marker elements

Say I have the list {{a}, {0, 2, 5}, {5, 4, 1}, {a}, {1, 1, 0}, {1, 4, 2}, {3, 3, 0}, {a}, {3, 2, 0}, {1, 4, 1}} I would like to make sublists of everything ...
11
votes
2answers
276 views

How to mesh a region using adaptive cubic elements

Assume a list of {x,y,z} coordinates. The coordinates are arranged in a regular fashion through a fixed raster size (called ...
11
votes
6answers
408 views

For a given expression: if it appears, remove it, but if it is absent, add it

While reformatting Szabolcs's code from (42660) I noticed this interesting operation: ...
11
votes
4answers
183 views

Faster position-based duplicate removal in a ragged array?

Take a ragged 2D array: rArray={{4, 2, 1, 0}, {2, 2}, {0, 0, 3, 3, 3}, {4, 0}, {3, 4}} I need to "deduplicate" this, where a duplicate is any element of a ...
11
votes
3answers
305 views

Threading over a list of lists of lists and a list of atomic expressions

Although I solved the following problem using MapThread, I'm curious about why Thread does not work as I expect it to here. ...
11
votes
3answers
198 views

Why can't I use Sequence to perform a Select like task? [duplicate]

Suppose I wanted to write down a list of $p^2$, for $p$ a prime between $1$ and $20$. I would expect Table[If[PrimeQ[k], k^2, Sequence[]], {k, 1, 20}] to work. ...
11
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 ...
11
votes
5answers
548 views

Find all the possible ways of partitioning a list into a set of pairs of element

I have a list {x1,...,xN} where N is even, and I need to find all the possible ways to split it into pairs of elements, e.g. the ...
11
votes
1answer
233 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 ...
11
votes
1answer
305 views

How to find longest monotonic sequence?

I have a list, for example list = {2, 1, 3, 5, 4, 6} How to find longest ascending sequence of this list? There are two meanings of this question: Find the ...
11
votes
1answer
733 views

How to split a Dataset into training and testing for machine learning?

Suppose I have iris data In the Dataset Format. How to split the iris data Into training and testing for Machine learning? For example,Transform the data for Classify.