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

learn more… | top users | synonyms (3)

11
votes
3answers
179 views

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

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. ...
10
votes
4answers
312 views

MapThread with non-rectangular lists

MapThread works fine and dandy with rectangular list structures: MapThread[f, {{{a, b}, {c, d}}, {{1, 2}, {3, 4}}}, 2] ...
9
votes
5answers
327 views

How can I remove matching sublists from my list?

I want to use DeleteCases (or any appropriate function) to remove elements of a list, which in turn are lists of fixed size. The rule I wish to apply is that any ...
8
votes
4answers
305 views

Generate PrimePower counting function

Is there a way to generate a counting function for prime powers - i.e. to create a similar function to PrimePi, but including prime powers. The following will, of ...
8
votes
2answers
353 views

Retrieving duplicates from nested list

Consider the following: data={{1,a},{10,a},{5,b},{4,c}}; In my case duplicates are defined when for {x1,y1} and ...
8
votes
3answers
1k views

Why don't * and ^ work as I expected on matrices?

For example, this input... {{1, 2}, {3, 4}}*{{1, 2}, {3, 4}} produces this output... {{1, 4}, {9, 16}} and this input... ...
7
votes
6answers
200 views

How to join held Lists?

Let's say I have a = Hold@{2+2} b = Hold@{4+4} How can I get Hold@{2+2,4+4} ie join the two held lists ? More ...
7
votes
2answers
245 views

Programatically adding/retaining comments within a nested list

Is it possible to convert the following list of strings to computable numbers with the comments preserved? ...
6
votes
2answers
306 views

Finding the coefficient of a certain power in a generating function

I want to compute $(t^1+\dots +t^5)(t^2+\dots+ t^6)(t^3+\dots +t^9)$ and find the coefficient of $t^{15}$ for example. $t$ is an indeterminate Now in Maple this is simply as ...
6
votes
2answers
327 views

How can I find if the number of subsets for a list is very large?

I'm trying to find the following; Subsets[Range[2, 2300], {4}] but my computer gave the following error: ...
5
votes
1answer
333 views

Apply color function to matrix plot

I want to apply the following color rules to a large table of numbers. I have extracted a part of the table to use as an example. I would like to assign 5 different colors to 5 different ranges of ...
5
votes
2answers
472 views

How to combine elements of two matrices?

Given two matrices m1 and m2, e.g.: m1 = {{a1, b1}, {c1, d1}} m2 = {{a2, b2}, {c2, d2}} How can one obtain the following? ...
5
votes
3answers
436 views

Adding Lists Together

This is something that should be simple, but the documentation and other questions don't seem to deal with it. I can think of mechanically doing it through a loop, but I know there must be a better ...
5
votes
1answer
392 views

Using Partition to allow sublists of different lengths

As a minimal example, suppose I have a list of the integers from 1 to 25. Suppose I want to use Partition to partition the list into sublists of length 10 but ...
5
votes
4answers
420 views

Leveling peaks in list

Consider the following: data={2,2,2,5,3,3,3,6,1,1,1,0}; In[1]:=result=MyFunction@data Out[1]:={2,2,3.5,3.5,3,3,4.5,4.5,1,1,1,0} ...
4
votes
1answer
497 views

Why is there a huge performance gap using Map with more than 100 List entries

im using Map on a List like this: cube= {{1, 1, 1}, {1, 1, 2}, {1, 1, 3}, {1, 1, 4}, ... , {5, 5, 4}, {5, 5, 5}} Mapping the whole List with 125 entries takes ...
4
votes
4answers
256 views

Elegant Matrix Combinations

Suppose you have a matrix (mxn), simplified for illustration m= {{a, b, c}, {d, e, f}} And a set of combinations (simplified for illustration purposes but can ...
3
votes
0answers
93 views

Gather dependency on list order?

I get intrigued about Gather behavior on this post. I thought that Gather was invariant under list order? Here is the result I ...
3
votes
2answers
2k views

Calculating the distance between the coordinates in a list

I have a list of coordinates {{A[9, 4, 7], 0.0395174}, {A[1, 5, 0], 0.0163797}, {A[0, 7, 2], 0.0577425}, {A[2, 7, 5], 1.01313}} I want to find the distance ...
2
votes
4answers
682 views

ListPlot multiple datasets over same x-values

Is there a better way to enter my data into a list plot? ...
2
votes
1answer
228 views

Extracting information from list

I have a huge list that looks like this: ...
2
votes
1answer
420 views

RowReduce: Solving for the resource vector (a, b, c) in Augmented Matrix

Here are two examples: RowReduce[{{3, 1, a}, {2, 1, b}}] evaluates to {{1, 0, a - b}, {0, 1, -2 a + 3 b}} but ...
1
vote
3answers
145 views

Binning events with weights

I have two vectors, one containing sampled energies and the other one for each of these energies a weight: e(i) and w(i). I ...
1
vote
2answers
239 views

How to blend some colors on a curve

I need to define a color gradient on a 3D curve, but I'm having some problems with this. Suppose we have a 3D curve defined as a parametric function of some real variable ...
1
vote
1answer
211 views

Syntax for integrating over limits specified by a Table

I wish to use NIntegrate to compute multidimensional integrals. However, I don't want to manually input the limits for the dimensions. I want to store the ...
1
vote
2answers
419 views

Specifying parts from lists for plotting using Show

I have the following data: ...
11
votes
2answers
343 views

Conditional Gathering of lists

Just need a little help with the GatherBy / SplitBy function(s). I have a list of random numbers here: ...
7
votes
1answer
358 views
7
votes
4answers
228 views

Button's command is not evaluated in iteration

I wish I didn't feel like a newbie after several months, but... If I enter the following: Table[ Button[ "Number: " <> ToString @ i, Print @ i], {i, 1, 5}] ...
6
votes
8answers
287 views

Merging lists and adding common elements [duplicate]

I have two 2D arrays where some of the x-values are identical, L={{1,1},{2,2},{3,3}}; J={{0,1},{2,2},{4,4}}; I want to add these lists in the following way ...
6
votes
6answers
399 views

How can I merge two lists in a special way?

It's been over a year since I've used Mathematica, and I'm having a total brain fart on a home project. I'd like to take an existing list of lists, say, ...
5
votes
2answers
234 views

Better method for creating a tuple out of two lists

I just combined two lists using this method ...
5
votes
2answers
475 views

Add elements in a sublist

I have created a subset of arrays: ...
4
votes
2answers
201 views

Correlation with missing data

I have two lists, age and score, that I want to find correlation on for 50 people. For some people, the score is blank. Example data: ...
4
votes
5answers
1k views

Removing zero values from ordered pairs

I have some processed data, which are basically a collection of ordered pairs in the form: {{x1, y1}, {x2, y2}, ..., {xn, yn}} Ordered pairs which have either a ...
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: ...
3
votes
1answer
327 views

Select row from a table by column value [duplicate]

I have the following: animals = {{dog, black, 200}, {cat, white, 100}, {moose, brown, 500}, {zebra,black,100}} If this came from a SQL table called animals, ...
3
votes
7answers
355 views

Concise way to generate multiset lists

I wrote the following to generate a multiset with the same number of items over a fixed range: ConstantArray[#, 3]& /@ Range[9] // Flatten ...
3
votes
3answers
177 views

Picking certain pairs according to a condition [duplicate]

I'm a Mathematica beginner and can't find out a solution to my problem. I have a list of pairs of numbers, for example something like this, but much longer: list={{2., 3.}, {3., 2.}, {5., 4.}, {4., ...
3
votes
5answers
466 views

How to combine some elements of a list?

In order to simplify my expression, I face a list manipulation problem. For example, given the input list ...
3
votes
2answers
503 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 ...
3
votes
1answer
210 views

Exchange axes in ListLinePlot

I'm sorry to do this right off the bat, but I have the following set of data: ...
2
votes
2answers
141 views
2
votes
3answers
156 views

Join matrix based on conditions

Given the following matrix: ...
2
votes
1answer
225 views

Selecting every last element of a nested list

I couldn't find a similar question so I decided to ask this one. I have a nested list with many sublists of equal length. To make things easier let's say it's like that: ...
2
votes
2answers
65 views

Specifying an array with a specific number of copies of two elements

To specify an array of length L in Mathematica, where each entry is someElement, I'm accustomed to writing: ...
2
votes
2answers
119 views

Can you form a list with elements which are terms from an equation?

Is there a command that takes an equation as an input and creates an output with a list of terms in the original equation? Something like: ...
2
votes
2answers
129 views

Total elements of a list that have a common first element [duplicate]

Possible Duplicate: List-operations only when restrictions are fulfilled (Part 1) I have a set of data like: ...
2
votes
3answers
477 views

Generating pairs of additive and multiplicative factors for integers

Given an integer $n$, I want to get two lists: a) the set of pairs of the divsors $a,b$ into exactly two factors $n=a\cdot b$, b) the set of pairs $a,b$ of two summands $n=a+b$. The code I ...
2
votes
0answers
331 views

Generating a function which outputs possible chemical reactions

I want to make a list of chemical reactions and I write them down in a $\require{mhchem}\LaTeX$ format. They are of the following form $$NA_n^i+MB_m^j \rightarrow \hat NA_{\hat n}^{\hat i}+\hat ...