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

learn more… | top users | synonyms (3)

9
votes
8answers
524 views

Adding elements to a collection of lists

I would like to add element a at the start of a series of lists. For example I have a collection of lists called ...
6
votes
3answers
925 views

print the name of the variable in a list without evaluation

a := az + 1 b := bz + 5 list := {a, b} I'd like mathematica to print a = az + 1 b = bz + 5 so basically it needs to first ...
13
votes
5answers
543 views

Interlacing a single number into a long list

This seems like it should be a simple question, but I am running into some difficulty in doing this with Mathematica. Right now, I have a list like this: ...
6
votes
1answer
415 views

ReplaceAll inside an Iterator

I'd like to apply a set of rules to an expression defining the iterators of the table, like this: ...
19
votes
3answers
441 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. ...
2
votes
3answers
630 views

Problem with Union and Intersection

Consider the following: list={{a,b,c},{c,d,e},{d,e,f},...{x_,y_,z_}}; I would like to apply Union on the elements of the list ...
14
votes
2answers
519 views

Reproducing nested loops using Map?

I keep producing bits of code like the following: ...
5
votes
4answers
2k views

Append in For loop does not work

I need to break my for loop in case of an thrown message and append s to the result list. Breaking the loop works, but my result is empty. I can not use Table[] ...
4
votes
3answers
972 views

How to replace all occurrences of an element in a list?

Consider the following: list={1,2,2,2,3}; I would like to replace all 2 with the string "Test". ...
8
votes
5answers
2k 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 ...
13
votes
7answers
737 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". ...
2
votes
1answer
370 views

Symmetric difference of a sample of lists

Consider the following: list1={a,b,c,d}; list2={c,d,e,f}; list3={g,d,c,h}; Now I would like to get the symmetric difference. Hence, the result must be ...
5
votes
1answer
565 views

Computing the distance between two curves obtained from image data?

I've got some image data that I've binarized. The image contains two curves, from which I'd like to compute the distance between (eventually computing an average radius for each point in the ...
7
votes
2answers
252 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: ...
2
votes
1answer
455 views

Adding rules to permutations

How can I calculate only those permutations of Range[n], that satisfy certain rules? I don't want to filter the result after calculating all the permutations but ...
2
votes
1answer
180 views

List-operations only when restrictions are fulfilled (Part 2)

Consider the following: data={{{3544128000, 80}, {3544732800, 80}, {3545337600, 80}, {3545942400, 80}, {3545942400, 160}, {3546547200, 160}, {3547152000, 0}}}; ...
12
votes
7answers
544 views
2
votes
2answers
130 views

A question about transforming one List into two Lists with additional requirements

Background: I create geometric patterns by applying many linear transformations on geometries, I need functions to weed out the exponentially increasing number of ( unnecessary ) points involved which ...
9
votes
3answers
267 views

Splitting a list in which figures vary from negative to positive

Consider the following list: data={4078, 256, -1266, -388, 1290, 1368, 1446, 1524, 2}; I would like to split any kind of such list always, when figures turn form ...
14
votes
5answers
875 views

Picking random items out of a list only once

I'm trying to create a function that randomly returns a value from a list but remembers the values that have been given before. At the end when the list is empty it should return an empty list. ...
7
votes
3answers
583 views

Add lists with unequal lengths together to create a matrix

I'm trying to create a stacked bar chart using raw data coming from a MySQL server. The result coming back from one query is: ...
10
votes
6answers
633 views

How to Map a subset of list elements to a function?

How would you, given a list {1, 2, 3, 4}, apply a function f to 1 and ...
12
votes
2answers
491 views

Are there advantages to using generalized Part extraction instead of specialized functions like First, Last?

There are many ways to extract different parts of lists in Mathematica. For example, the first part of a list v can be accessed either as ...
10
votes
8answers
2k views

Map and Apply a function on a nested list

I have a list like this: {{1,2}, {4,2}, {6,4} ... } I want to replace every second number with a function of that number. For e.g. ...
3
votes
3answers
255 views

Combining heads of lists so that you can create a nested list from two sublists

I have a list such as list = {1,4,3,4,6,3,1,2,3,4 ... } and a range, say, range = Range[20000]. I want to obtain the following ...
13
votes
5answers
746 views

How to thread a list

I have data in format data = {{a1, a2}, {b1, b2}, {c1, c2}, {d1, d2}} Tableform: I want to thread it to : ...
4
votes
1answer
233 views
7
votes
3answers
514 views

How to create a list of pre-defined functions?

I would like to create a list of Cauchy distribution pdf's, having different locations of their maxima, and being multiplied by different factors; then I'd like to calculate those functions' values ...
31
votes
6answers
2k 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 ...
30
votes
7answers
2k 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: ...
8
votes
2answers
423 views

Handling vector comparisons in “Piecewise” function

Is it possible for the Piecewise function to process a vector comparison? For example, my input vector is x={0,1,2,3,4} I would like to define a function that ...
2
votes
1answer
161 views

Issues with a Counter that is tallying term appearances

I am working with an array of textfiles, trying to see how frequent certain terms are. However, I am running into some difficulty with my running counts of bigram frequency. Here is a snippet of my ...
26
votes
2answers
938 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 ...
10
votes
1answer
585 views

Modifying a List in a function in place [duplicate]

An example will be most specific: func[list_, column_] := list[[All, column]] = Map[#*2 &, list[[All, column]]]; This throws errors. I want to avoid doing ...
27
votes
9answers
669 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 ...
4
votes
2answers
299 views

Why can't NumberQ be used as the head of a pattern?

Consider the following: list={1/First[{}], 1, 2, 1/First[{}], 3}; DeleteCases[list,_NumberQ] I wanted to remove all cases, which did not match ...
10
votes
3answers
313 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: ...
11
votes
2answers
342 views

Conditional Gathering of lists

Just need a little help with the GatherBy / SplitBy function(s). I have a list of random numbers here: ...
17
votes
4answers
308 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 ...
2
votes
2answers
297 views

MapThread on a nested Map

A simple problem I am facing is here: ...
4
votes
1answer
310 views

Path queries for tree-structured data

Can anyone suggest documentation or tutorials for developing path queries and indices for (XML-like) tree-structured data? Suppose data is organized hierarchically in key->value pairs, eg: ...
-1
votes
1answer
391 views

variable sized lists and using lists as variables

I am trying to scan a parameter space of varying numbers of parameters subject to some constraints (I am interested in any number of constraints just out of curiosity, but in reality no more than 2 ...
4
votes
1answer
538 views

How do I treat elements in a list as variables inside a module?

I want to be able to assign values to a list element inside a module. For example if I have: ...
9
votes
4answers
277 views

Make a ragged list rectangular by trimming instead of padding

I have a ragged list ragged = {{a,b,c,d,e},{x,y,z}} that I would like to trim (on the right) to be rectangular. The desired result is ...
12
votes
2answers
1k views

Simple algorithm to find cycles in edge list

I have the edge list of an undirected graph which consists of disjoint "cycles" only. Example: {{1, 2}, {2, 3}, {3, 4}, {4, 1}, {5, 6}, {6, 7}, {7, 5}} Each ...
13
votes
7answers
750 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 ...
9
votes
6answers
2k views

extract values from replacement list

Solve returns a list of replacement rules In: Solve[x + y == 3 && x - y == 6, {x, y}] Out: {{x -> 9/2, y -> -(3/2)}} I am only interested in the ...
13
votes
4answers
804 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 ...
15
votes
7answers
7k 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 ...