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

learn more… | top users | synonyms (3)

10
votes
5answers
424 views

How would you efficiently implement BinListsBy?

Let's say I have a list like this: data = {{21, "Alice"}, {27, "Bob"}, {22, "Charles"}, {34, "Dora"}, {75, "Eliza"}} containing ages and names of persons. What I ...
1
vote
1answer
76 views

Nest Replace Function with different rules

I have a table of data that I want to filter. Any value of zero in the table means that value was not calculated, so it should get populated with the tag "NC". Next the table is filtered for all ...
2
votes
2answers
94 views

What is wrong with my use of Flatten? [closed]

Why does Flatten[f[g[a, f[b]], f[c, d]]] result in f[g[a, f[b]], c, d] I expected the answer to be ...
3
votes
2answers
86 views

Find Lists with intersecting sublists

I have a list of the following form: ...
1
vote
1answer
65 views

Is this the expected behaviour from Partition when padding is inserted at the start of the list?

The documentation for Partition shows an example of partitioning without padding, so that no elements are dropped, but the last sublist can be shorter. ...
1
vote
1answer
109 views

Check every list element for appearance

I'm used to MATLAB so this might be a stupid question but Mathematica is freaking me out. I have a big matrix with the following format: ...
0
votes
5answers
72 views

Merge two lists for List3DPlot [duplicate]

I have a two lists: list1 = {{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}, {x5, y5}} and list2 = {z1, z2, z3, z4, z5} and I want to ...
0
votes
0answers
32 views

Grabbing columns from a matrix [duplicate]

If I have a matrix - exampleMatrix = {{A1,B1,C1},{A2,B2,C2},{A3,B3,C3}}; And I want to create a matrix like - ...
15
votes
6answers
1k views

Best way to extract values from a list of rules?

Mathematica has a lot of list manipulation functions, and, also because I don't work with lists often, at times I'm a bit lost. I'll find a way, but I'm sure it's not the most efficient. Case in ...
3
votes
3answers
203 views

How can I extract multiple spans from a list?

I know in Mathematica, I can do A = Range[100]; B = A[[50 ;; 60]] B will then contain the 50th through 60th elements of A. Now, what if I wanted B to take 10th ...
1
vote
2answers
86 views

Clearing arguments passed to a Module

Is there a possible way to clear the arguments passed to a module to release some memory. I believe that arguments passed to modules are passed by value rather than pass by reference. e.g. I have the ...
2
votes
3answers
179 views

Using Part rather than Extract

In my work I found that I needed the Extract function. However I was wondering if there was a way to use Part. Assume that ...
4
votes
2answers
129 views

Replacing one element of list

I have a list of sequences of x's and y's. I want to switch the last position to the "opposite" symbol - if ...
3
votes
8answers
338 views

How to add a column to a table that counts the number of times the lines appear?

I am at a complete loss at this. I have a table with 2 columns and n lines. Some of the lines are repeated. What I want to do is add a new column that counts the number of repetitions of each line. ...
0
votes
2answers
80 views

Extract X value from corresponding Y value from a List or Transpose [closed]

I have a list of X values and Y values separately, and also together with: data=Transpose[{X,Y}] This data is from a chromatogram, and I want to extract the ...
6
votes
4answers
359 views

Generating an Ulam spiral

An Ulam Spiral is quite an interesting construction, revealing unexpected features in the distribution of primes. Here is a related topic with one answer by Pinguin Dirk, who has provided one ...
0
votes
1answer
63 views

Select duplicate values from a list [duplicate]

How can I select the duplicate values in a list? Example: {1, 2, 1, 1, 1, 1}
2
votes
3answers
419 views

Convert a string into a list of numbers

I got the following problem I don't know how to solve or if it's at all possible to solve(I'm quite new to Mathematica and don't have an IT background, so please explain slowly if possible:)) I'm ...
3
votes
2answers
214 views

Dealing with a huge dataset

I have two ingredients here: a big dataset contained in a list, with ~ 20M values. a function that takes as each element of the list as input and yields True or False I want to save somewhere the ...
0
votes
3answers
142 views

Trouble understanding a piece of code found on Wolfram Blog

I am trying to go through this Wolfram Blog example: http://blog.wolfram.com/2009/02/12/flag-analysis-with-mathematica/ on country flag analysis. I am having a problem understanding the following ...
3
votes
3answers
94 views

How to test if all the elements in a list are Integers? [closed]

Consider a list such as s={1,2,3,3,5,6,3} With IntegerQ[number] , you know if number is an ...
1
vote
2answers
64 views

Replacing a specific pattern of values at level 2 in a list

I've a list of lists, tl = {{True, False, m12}, {False, m22, m33}, {m32, False, True}} and each nested list has the same length, What is the proper way to ...
2
votes
3answers
110 views

Delete Missing data from coordinate sets

I have a list of pairs of coordinates, where some are missing. ...
2
votes
2answers
127 views

Permuting elements within a list

I have s = {2, 3, 5, 7, 1, 4, 6} (* always with diffente elements in {1,2....7}*) l = Length[s] n = 3 and n tells us that we ...
5
votes
3answers
223 views

Split list of states by run lengths and discontinuous changes in state

I was asked to look into writing some simulation code for a user, where the simulation output (x) would oscillate between three possible states: ...
2
votes
2answers
87 views

Importing Data and Devoting Their Names to Them

There are some files in a directory. I have used of SetDiroctory to access all of them. SetDirectory["C:\\Users\\SE7EN\\Desktop\\mathematica\\test"]; I can visit ...
1
vote
2answers
141 views

Generating list of coordinates in $\mathbb{Z}^n$ given by set of inequalities

I am trying to generate list of coordinates that forms a subset in the integer lattice $\mathbb{Z}^n$. This set is given by set of inequalities. Right now, I am using the following: ...
0
votes
1answer
43 views

Resolving Error: Mathematica evaluation order on Lists

I have a table that is 27 x 27, each entry corresponds to an element from the periodic table. I use the replacement rules in element list to allow me to convert a list of elements into a list of ...
0
votes
1answer
146 views

How to load data into a Manipulate expression

I have data showing truncated octahedron geometry changing with time. How can I read those data into a Manipulate expression? To be specific, I want to manipulate ...
3
votes
2answers
177 views

make a list based on two other lists

I have two lists: list1={4,6} list2={1,2} and I now want a function f that produces f[list1_,list2_]:={1,1,1,1,2,2,2,2,2,2} ...
8
votes
4answers
278 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 ...
2
votes
1answer
44 views

Complement for a Matrix

In a matrix, there are some non-zero elements same as: aA= Also, there is a list such as: list = {a, b, c, d, e, f, g, ii, jj, kk}; I want to access to ...
1
vote
0answers
35 views
4
votes
3answers
375 views

Efficient matrix / array generation

What is the most efficient way of generating the following matrix? $\left( \begin{array}{ccccc} 1 & 0 & 1 & 0 & 1 & 0 & 1 & \dots\\ \frac{1}{2} & \frac{1}{2} & 0 ...
2
votes
2answers
90 views

select from a list based on digits

I wish to know how do I count the number of occurrences of numbers that end in digits d. e.g. Say I create a list of Divisors of 12! I now want to count those divisors that end in 12. Like 12 & ...
0
votes
0answers
77 views
8
votes
2answers
348 views

Aligning two lists

I have two lists, L1 and L2, each with a key and some data. Let us say the key is a person's name, a string, and the data follows. (To respond to rasher's query:) Let us also assume the lists are ...
0
votes
2answers
84 views

How do I perform the riffle function backward? [duplicate]

I know riffle will combine the lists {1,2,3} and {a,b,c} to be {1,a,2,b,3,c}. Is there a way to work backward and split the list {a,b,c,d,e,f} to be {a,c,e} and {b,d,f}?
0
votes
1answer
71 views

how to apply a function to a list of tables

I have several files, and I want to extract for each of them a table, and then select just numbers, and keep only rows with five elements. My code works fine during import ...
22
votes
3answers
481 views

Undocumented form for Extract

Prompted by a comments conversation here, here's an interesting (and often performance enhancing) use of Extract: ...
1
vote
2answers
133 views

position of element in a list using a function

How can I find in a list l the positions of all elements satisfying a boolean function f. For example, how can I pick in ...
3
votes
6answers
313 views

How can I construct a distance table?

I have a list of city names (of arbitrary length), f.e. c = {"BAL", "NYC", "LAS", "AUS"}; and the distances between them : ...
6
votes
7answers
1k views

How to select all elements above the main diagonal of matrix?

How to select all elements above the main diagonal of matrix? I need to create a list of them.
1
vote
2answers
145 views

Find equal elements on a list

Consider the following code to produce the sequence $x_1,\ldots,x_{n+1}$ where $x_i=11\cdots1$ ($i$ digits 1). Is there an easier way to do this? ...
1
vote
3answers
121 views

Working with nested matrices

I have a matrix: A = {{a, b}, {c, d}} But each its element, itself, is another matrix too. ...
2
votes
1answer
91 views
40
votes
6answers
3k 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 ...
3
votes
1answer
117 views

Sectional averages of a list

I am working in Mathematica. I have a table of 200 elements. I want to calculate the mean value for the first 20 elements, for the second 20 elements and so on, up to 200. I will get a table (matrix) ...
0
votes
1answer
54 views

Taking Mean for several elements of a list [duplicate]

i have the following question: Let us assume we have the following list: list={1.1,1.2,1.0,2.1,2.2,2,0,3.1,3.0,3.2} I need a function that always takes three ...
0
votes
2answers
150 views

How to pass a list as function argument?

I have the following function lFreqPhylo[a_, Q_, b_, p_] := Sum[Log[freqFunction[r[[p]][[i]], L[[p]][[i]], a, Q, b, {i, 1, nbranches[[p]]}]; The objects L, r ...