Questions on the manipulation of List objects in Mathematica, and the functions used for these manipulations.
30
votes
6answers
4k views
Elegant operations on matrix rows and columns
Question
The Mathematica tutorial has a section 'Basic Matrix Operations', describing operations like transpose, inverse and determinant. These operations all work on entire matrices. I am missing a ...
29
votes
6answers
2k views
Does Mathematica have advanced indexing?
I have two $M \times K$ arrays $L, T$ where I would like to set all the elements in $L$ to zero whenever the corresponding element of $T$ is greater than 15. The ...
28
votes
2answers
595 views
Tiling a square
I wondered if there was a way to automate the process of finding a way to tile a tile into a square.
The idea is to represent the tile with a matrix of 0s for blank space and 1s for filled spaces ...
27
votes
6answers
1k views
How to visualize/edit a big matrix as a table?
Is it possible to visualize/edit a big matrix as a table ? I often end up exporting/copying big tables to Excel for seeing them, but I would prefer to stay in Mathematica and have a similar view as in ...
27
votes
4answers
560 views
Filtering beat-to-beat heart rate data
From an experiment, I have a dataset of beat-to-beat heart rate data: a list of the time between each heart beat in [ms].
The data is measured using an infrared optic sensor at the finger tip. The ...
26
votes
6answers
901 views
Find zero crossing in a list
I'm looking for a function that finds the index of the zero-crossing points of a list. Before I go making my own subroutine to do this, I was wondering if anyone knows of any built-in Mathematica ...
25
votes
4answers
661 views
Partitioning with varying partition size
How can I partition a list into partitions whose sizes vary?
The length of the $k$'th partition is a function $f(k)$.
For example: if $l = \{1, 2, 3, 4, 5, 6\}$ and $f(k) = k$. Then
the partitioning ...
25
votes
2answers
349 views
DeleteDuplicates not deleting duplicates
It is not surprising that DeleteDuplicates[{5,5.}] returns {5,5.} because DeleteDuplicates ...
23
votes
12answers
818 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 ...
23
votes
7answers
978 views
How to apply or map a list of functions to a list of data?
Say I have a group of functions:
f1[a_] := a * -1;
f2[a_] := a * 100;
f3[a_] := a / 10.0;
and some data in a list:
...
23
votes
8answers
1k views
Levels: how do they work?
I cannot understand how Mathematica manages levels, and so it's always a painful try-and-fail to use Flatten. Can someone please give me a very clear definition?
...
23
votes
6answers
1k views
How to select minimal subsets?
I am a newbie, so please point me in the right direction if you feel this question has been answered somewhere else before. Here goes:
Suppose I have a list like this:
...
23
votes
2answers
464 views
Transpose uneven lists
Is there a quick method to transpose uneven lists without conditionals?
With:
Drop[Table[q, {10}], #] & /@ Range[10]
Thus the first list would have the ...
22
votes
4answers
838 views
Clustering of space-time data
Below is an example of a gaze sequence I recorded during a 3 seconds display. That is, where the eye was at every millisecond. While we should have 3000 points, we are missing some due to blinking.
...
20
votes
3answers
375 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:
...
20
votes
2answers
698 views
Populating and storing a very large array in Mathematica
I am using Mathematica 8 to generate a very large multidimensional array of floating-point numbers and then store it in a file. Typical array sizes are 10000 x 50 x 15 x 40, resulting in a 3-4 GB ...
19
votes
5answers
995 views
What is the most efficient way to add rows and columns to a matrix?
Say I have a matrix m and a vector v.
...
19
votes
2answers
693 views
Extracting values from nested rules in JSON data
I have been using Mathematica to analyse some data from the StackExchange API. It is conveniently available in JSON form, which Mathematica interprets as replacement rules. However, some of the rules ...
19
votes
3answers
388 views
Is there a faster way to create a matrix of indices from ragged data?
I have data that is given as a list of ordered pairs mixed with scalars. The pairs can contain infinite bounds. My goal is to convert the data into an index used in future computations.
...
19
votes
3answers
323 views
How can I regroup elements in a list into a tree based on their values?
I have a list of elements in an outline, here is an example that is only 3 levels deep:
...
18
votes
7answers
420 views
Sequentially numbering a nested list
I've got a nested list
{a, b, {c, d}, e, {f, {g, h}}}
which I want to magically transmogrify to
...
18
votes
6answers
778 views
efficient way to count the number of zeros at the (right) end of a very large number
If I want to count the number of zeros at the (right) end of a large number, like $12345!$, I can use something like:
Length[Last[Split[IntegerDigits[12345!]]]]
...
18
votes
4answers
554 views
Sort lists according to the order of another
I have three parallel lists (i.e. the elements in position i of each list are related). I want to sort the first list using the function Sort and make the same changes to the other lists so that I ...
18
votes
6answers
813 views
18
votes
11answers
645 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 ...
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 ...
17
votes
7answers
694 views
Selectively Mapping over elements in a List
I am using the following code to easily generate a row of images of all eight planets of our Solar System:
...
17
votes
3answers
347 views
How to efficiently find positions of duplicates?
Is there an efficient way to find the positions of the duplicates in a list?
I would like the positions grouped according to duplicated elements. For instance, given
...
17
votes
4answers
216 views
Setting parts of a list
Suppose I have list
a = Range[10]
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
in which I want to set some elements to be a list
...
17
votes
1answer
533 views
How can the {x,y,z} points that fall on the outer boundary of a set of values be selected and smoothly surfaced?
For a given set of x,y,z values, that may, or may not form a uniform shape, how can the center of the data cloud be found, and the surface points be located and a solid smooth surface created from ...
16
votes
8answers
424 views
Applying And to lists of Booleans
I'd like to take {True,True,False} and {True,False,False} and apply And to get ...
16
votes
5answers
2k views
How to find the phase difference of two sampled sine waves?
I'm trying to measure a phase difference between two Sine functions I've acquired with a computer. I'm uploading one of the .txt files with the data I'm working with here: txt file. To remove the ...
16
votes
7answers
812 views
How to Derive Tuples Without Replacement
Given a couple of lists like a={1,2,3,4,6} and b={2,3,4,6,9} I can use the built-in Mathematica symbol ...
16
votes
1answer
237 views
Using Transpose with a list as the second argument
I'm having difficulty understanding the Transpose function. I know what the transpose of a matrix is, not a problem, and I see that applying the ...
15
votes
8answers
537 views
How do you check if there are any equal arguments(even sublist) in a list?
I would like to set up a function which has to return True if at least two arguments of a given List are equal.
So if I give {1,4,6,2} to the function it has to ...
15
votes
5answers
399 views
Map-Thread-Through-Apply a list of functions onto a list of (lists of) values
I have a list of functions:
fns = {f, g, h}
and a list of triples:
...
15
votes
4answers
342 views
Splitting a list
Please consider the following list:
data={1, 0, 0, 0, 2, 5, 2, 3, 0, 0, 3};
Now I would like to split the list into 0-sequences and Not-0-sequences as following:
...
15
votes
1answer
222 views
Are there advantages to using additional arguments of common functions rather than alternative ways of calculating with lists?
(Apologies for the long question title.)
One of the interesting, if sometimes confusing, things about Mathematica is that there is always more than one way to do things. Even intermediate users can ...
14
votes
10answers
390 views
Using MapAt to map at a particular depth (levelspec)
I have the following sample list (my actual list is, of course, much longer):
...
14
votes
7answers
3k 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
5answers
418 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,... ...
14
votes
6answers
384 views
Splitting a list by specifying section headers
I have a list of strings called mylist:
mylist = {"[a]", "a", "a", "[b]", "b", "b", "[ c ]", "c", "c"};
I would like to split ...
14
votes
3answers
2k views
K-means clustering
In MATLAB, there is a command kmeans() that divides an array into $k$ clusters and calculates the centroid of each cluster.
Is there any command in Mathematica to ...
14
votes
6answers
852 views
Insert $+$, $-$, $\times$, $/$, $($, $)$ into $123456789$ to make it equal to $100$
Looks like a question for pupils, right?
In fact if the available math symbol is limited to $+$, $-$, $\times$, $/$ then it's easy to solve:
...
14
votes
4answers
370 views
Implementing a function which generalizes the merging step in merge sort
One of the key steps in merge sort is the merging step. Given two sorted lists
sorted1={2,6,10,13,16,17,19};
sorted2={1,3,4,5,7,8,9,11,12,14,15,18,20};
of ...
14
votes
6answers
337 views
Elegantly pairing up mismatched lists
HistogramList returns a list of bin boundaries and a list of counts. There is one more boundary than counts, and I'd like to pair them up so I can feed it into ...
14
votes
3answers
353 views
Using pure functions in Table
I need a table with the elements made of pure functions and list elements. This is a simplified example:
I need a list as:
...
14
votes
6answers
483 views
On generalizing Partition[] (with offsets) to sublists of unequal length
The usual Partition[] function is a very handy little thing:
...
13
votes
10answers
618 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:
...
13
votes
7answers
613 views
Selecting a sublist based on Length
If you have a simple list of lists as follows:
test = {{1, 2}, {4, 5, 6, 7}, {5, 4, 3}}
How do you ask Mathematica to return the sublist of greatest length?
...


