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

learn more… | top users | synonyms (3)

14
votes
8answers
1k 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? ...
10
votes
2answers
152 views
+100

Enumerating tuples from a larger space such that all pairs of values are present at least once

I am trying to write a function that will accept a list of N lists and returns a list of N-tuples that represent all pairs of values from the original N lists at least once. To illustrate with an ...
0
votes
2answers
51 views

NSolve gives {{ x -> #}}, How do I make x = #; I need to use the x value again later

I want to use: demand = {1.92, 2.07, 2.37, 2.72, 2.87}*10^6; NSolve[SetV == demand[[1]]/(Cpf (1 - χ)), χ] I want to make a vector of solutions ...
-2
votes
1answer
45 views

Create a matrix by crossing a list

I've a list L of elements. I want to create a matrix by laying each elements of L in both rows and columns where each ...
2
votes
3answers
72 views

Comparing two lists lexically

I have two lists of integers a and b of equal length, and I would like to define a>b as ...
5
votes
5answers
450 views

Efficient Indexed Sort

Suppose I have a preference for animals given by: orderOfAnimals = {"dogs", "cats", "fish", "elephants", "giraffe", "hamsters", "poodles"}; I'm given many data ...
2
votes
1answer
33 views

How can I use parts of lists with Dynamic?

I'm a newbie - what am I doing wrong? I want to use parts of lists (vectors) in calculations but Mathematica will not evaluate anything that involves parts of lists that update dynamically. Is there a ...
0
votes
0answers
30 views

SubsetQ returns unevaluated

I am using Mathematica 10.0.1.0, on Ubuntu 14.04.1. Executing SubsetQ[{1, 2, 3}, {1}] returns the same expression unevaluated: ...
1
vote
3answers
62 views

List Manipulation Via Conditionals

I'm trying to convert one list to another by applying a condition on the list's elements. But I can't figure out how to do this in mathematica's language. Python example below ...
1
vote
2answers
255 views

What quantity is this “length” called?

tmp = {x, y, z}^{1, 2, 3} Times @@ tmp Length[%] This gives a length of 3. But I was expecting 1. What is exactly this "length" of x*y^2*z^3 called? I would ...
1
vote
1answer
123 views

Mathematica List Selection

I have a list which contains these elements : ...
1
vote
1answer
103 views

Finding the index of (x,y) pairs in a list

I have a large list of $(x,y)$ pairs, and I want to find the index of a particular pair in order to extract some data from another array. By way of an example, ...
0
votes
1answer
48 views

Why `Delete` does not work?

I'm trying random thing in Mathematica just for learning and I can't solve this problem. I want to use the Detele function to delete some elements in a list but ...
2
votes
1answer
53 views

Displaying a list in form of an upside down pyramid graphic

I was wondering how to display a list like this: list={{0,1,1,0},{1,0,1},{1,1},{0}} in form of an upside down pyramid, that is the first element of the list is ...
5
votes
3answers
730 views

How to build this grid with less code?

I have the diagonal and both upper and lower triangulars of a grid. ...
0
votes
0answers
34 views

How to combine several graphs in one? [on hold]

If I have table of for example 5 sets of points which form 5 curves, to plot all of them in the same graph I use this: ...
1
vote
2answers
116 views

Merging two lists with possible different keys

This is very similar to my earlier question One to Many Lists Merge but somehow different. I have two lists, first column in each list represents its key. I want to merge these two lists. The only ...
3
votes
2answers
59 views

How to keep first observation and delete other observations of each group in unbalanced Panel data

I have a huge panel data. I want to create a new data keeping only first observation of each group. How can I achieve it? For illustrative purpose; ...
5
votes
2answers
255 views
2
votes
3answers
156 views

Splitting a list of lists (part2)

This is a follow up from Splitting a list of lists . What would be a nice way to split the list l1 = {1,2,{a,b,c},3,{d,e}} into ...
0
votes
1answer
58 views

Duplicate values n-times [closed]

I already asked how I can take the list {1,2,3} and get {1,1,1,2,2,2,3,3,3} out of it, adding degeneracy to the problem. So far ...
6
votes
6answers
271 views
0
votes
3answers
67 views

Splitting a list of lists

What would be a nice way to split the list list = {1,2,3,{a,b,c},4} into {{1,2,3,a,4},{1,2,3,b,4},{1,2,3,c,4}}
3
votes
3answers
174 views

Pare down list recursively

What is the best way to pare down a list whereby the $n$th number is removed from the list recursively? This ...
0
votes
0answers
39 views
8
votes
5answers
417 views

How to subtract one list from another, treating each elements as distinct?

Suppose that I have a = {"A", "A", "A", "B", "B", "C"} b = {"A", "B"} How can I subtract b from ...
1
vote
7answers
94 views
1
vote
1answer
30 views

Generate Degeneracies in List [duplicate]

I have a list with n entries and I would like to duplicate this list p times. In my case because of the Degeneracy of my Eigenvalues. For example I have {3,2,1} and it is five-fold-degenerate so that ...
1
vote
2answers
62 views

How do you apply an algorithm individually to an array with many graphs

I have and array with many graphs to which I want to apply an algorithm (below) to each graph in an array that contains all my graphs. ...
2
votes
2answers
108 views

Understanding `NestList` with multiple functions

General question For a function f[n, a], where a is a list and n is a whole number, what is ...
3
votes
3answers
156 views

How to detect outlier in data of an unknown function $f(x)$

Suppose I have an unknown function $f(x)$ that is monotonic, convex and nonlinear by definition. I somehow evaluated it at 1000 nonuniform $x$ points. By ploting these data, I found a very obvious ...
2
votes
3answers
138 views

Deleting missing data with CountryData

I need to delete all of the missing entries after executing this line: ...
2
votes
0answers
54 views

Choosing a List as VertexWeight for a TreeGraph

I would like to map every vertex of my TreeGraph to an List. ...
8
votes
1answer
205 views

Transformation rule on a list of non-negative integers

I am trying to create a transformation rule that takes a list of non-negative integer values of any length, finds a non-zero entry in the list, adds 1 to all preceding numbers, subtracts 1 from the ...
4
votes
3answers
158 views

Polynomial with alternating sign coefficients from the odd degree terms of a Truncated Power Series

I'm trying to make a function that will take any truncated power series I give it, strip away all the even degree terms, then change the sign of the coefficients of every other term. So that we have a ...
0
votes
2answers
83 views

Finding an idiomatic way to express a system of linear equations

I have an $n$ x $n$ matrix $T$, where $t_{ij}$ is the element at the $i\,$th row and $j\,$th column, and unknowns $x_i$, $1\leq i \leq n$, where $$x_{n} = 1$$ $$x_{n-1} = 0$$ $$x_i = \sum_{1\leq j ...
0
votes
1answer
70 views

Recursive functions taking list arguments

I wish to create a function that takes lists (e.g. {plus,plus,minus,0,minus,plus}) and uses the input list to calculate a corresponding value using a set of ...
5
votes
3answers
125 views

Missing control for depth of Inner

Working on a mechanics problem, I stumbled on something peculiar: Since Inner is a generalisation of Dot, it changes its ...
1
vote
2answers
45 views

How to add a part of a list to a function?

I want to be able to add a specific portion of a list to a part of a function but this fucntion intakes 6 variables where as the list is of example: ...
3
votes
3answers
77 views

Generating increasingly longer lists from a single list

I start with an array such as {{1,1},{0,1},{-1,1}}. (1) I want to create an array from this which replaces each array inside the array with 3 new arrays, one ...
8
votes
3answers
141 views

Complicated list slicing

Say I have a list with the structure list = {{1, {x1, y1, z1}}, {2, {x2, y2, z2}}, {3, {x3, y3, z3}}, ...} I would like to slice it such that I end up with ...
1
vote
1answer
70 views

Transform a rule to a list of rules

How can this rule a -> {1, 2, 3} be transformed into this {a -> 1, a -> 2, a -> 3} by way of a function? ...
12
votes
1answer
354 views

How can I collect data for visualization of quick sort?

I know how to implement quick sort in Mathematica. But I don't know how to get the temp data for visualization, because I used recursion. I want the effect similar to this: ...
0
votes
0answers
36 views

Using List/Histogram Data As A Weighted Function?

I have a list of data points that I would like to use as a weighted fucntion. The data represents the number of particles within a bin of a particle distribution. Ultimately I would like to multiply ...
15
votes
4answers
417 views

Exclude data from a list

Let's create some random sample data data = Table[{RandomReal[{-10, 10}], RandomReal[{-10, 10}]}, {i, 1, 300}]; Then we plot them using ...
8
votes
3answers
299 views

How to remove a line of a matrix if not all elements are numeric?

I have a matrix a n columns and m lines. I'd like to efficiently remove the lines that are not entirely composed of numeric ...
5
votes
0answers
125 views

How to download and combine S&P 500 stock prices

I want to download historical S&P 500 stock prices and combined them into one big file, having only one column of date referencing all stocks. Here is what I have do so far. ...
6
votes
5answers
541 views

What is the best way to draw a shaded table?

I'm trying to format a raster-style table with row and column headings and in which each cell is shaded according to the value in the cell, and the value of the cell is displayed in as text in a ...
10
votes
4answers
405 views

Building a tree

Given a list of word characters, such as this one, I'd like to build a tree, similar to this makeTree function, but with the tree in a different format. So, for an input such as ...
1
vote
1answer
37 views

Easy way to perform multiplication of two 2x2 matrices, that contain list elements?

I have two 2x2 matrices, which elements are lists (so overall structure can be complicated). I need to perform matrix multiplication of these 2x2 matrices as if the elements didn't have its inner ...