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

learn more… | top users | synonyms (5)

14
votes
4answers
289 views

Fast Selections Testing on Inequality

Is there a functional idiom for fast selections testing on inequality? For example, finding values from list a & b where the key is less than or equal to a value, in this case 4 or 9. An ...
4
votes
1answer
233 views

Select elements of list

I have a list of lists list={l1,l2,l3,l4,...}; and two elements e1,e2. I want to select from lists ...
2
votes
1answer
58 views

Manipulating and adding elements in a matrix [duplicate]

I have the following j = {{1, 2}, {3, 2}, {5, 4}, {1, 2}, {3, 2}} k = {1, 2, 3, 4, 5} t = SparseArray[j -> k, Max@j {1, 1}] The above creates a 5x5 matrix ...
0
votes
1answer
32 views

Extending the dimension of matrix and manipulating it

I have the following code a={{1,2},{4,3},{3,2}} b={3,4,5}; x=SparseArray[a->Table[0,{i,Length[a]}]] x=SparseArray[a->(Extract[x,a]+b)]; The above code ...
1
vote
6answers
225 views

Is there an existing way to add a comma between elements of a Scan?

Without thinking, I wrote (the equivalent of) this... ...
7
votes
1answer
90 views

fast complement with tolerance between large lists

I want a fast algorithm to get a list of elements to be kicked out of another list. But the kick out criterion is not the exact equivalence, however has a tolerance. Any two elements close enough are ...
8
votes
0answers
162 views

Efficient way to flatten or transpose-arrayreshape tensors

I have a tensor of dimensions $(2, 100, 100, 2, 100, 100)$ and I want to reshape it to a form of $(2*100*100,2*100*100)$, e.g. Flatten[A,{{1,5,6},{4,2,3}}]. If I ...
13
votes
4answers
370 views

How to evaluate the second argument of Cases only once

I'd like to find a fast but readable way to achieve the following: ...
5
votes
1answer
86 views

SplitBy problem with Associations

Association keys are supposed to be transparent, but in this reduced example SplitBy fails: ...
1
vote
1answer
60 views

Behaviour of RealDigits expected or wrong?

Is this behavior expected or a bug? RealDigits[10304.390456] {{1, 0, 3, 0, 4, 3, 9, 0, 4, 5, 5, 9, 9, 9, 9, 9}, 5} when I ...
3
votes
1answer
196 views

Animating N points

So I'm trying to create an animation of N interacting particles in two dimensions confined in a box. Generating the data is fine and it's being stored in a text file with two columns for each particle;...
2
votes
1answer
50 views

Path with no dependence violations

I am guessing this will be a duplicate(it seems like a common task), but I obviously can't find the right page. I have a directed graph showing dependencies, and I want to list the vertices in an ...
12
votes
3answers
522 views

Map a function of several arguments

I have three lists, e.g. list1 = {{a,b,...}}; list2 = {{1,2},{3,4},...}; list3 = {{x,y},{z,w},...}; and a function ...
10
votes
6answers
500 views

Unique Element in List

I have a list a, and want to find out whether there is a unique element in the list. For instance a={x,y,z,y,x} has an unique ...
3
votes
2answers
141 views

Given a list of positions in a matrix, get elements within radius r

I have a n x n binary matrix like SeedRandom[1]; mat = RandomInteger[1, {9, 9}]; MatrixForm[mat] I want to create ...
3
votes
2answers
66 views

Access all the elements of matrix from a list

I have a list of lists e.g: c=Table[i+j,{i,5},{j,5}] and a={1,2,3};b={3,2,5}; Now I want to access the elements of ...
3
votes
1answer
69 views

How can I extract parts of a mixed list? [closed]

I have the following list: lst = { {1, {{"abc", "bcd"}, {"cd", "efg", "fghi"}, {"g"}}}, {2, {{"abcd"}, {"bc", "cdef"}, {"defgh"}}} }; By using ...
19
votes
2answers
453 views

Upper bound “Vicious nearest neighbour” algorithm suggestions

I am asking a question based on this question from the sister site MSE. In an effort to make this a self-contained question, I include the fiorst documented posing of the problem by Robert Abilock in ...
3
votes
4answers
182 views

Filtering the close values from the list? [duplicate]

I found some difficulty to flatten the data. Let's say we have a list such that, list={-0.0223, -0.0199, -0.0195, -0.0159, -0.0159, -0.0122, -0.0126} You can ...
2
votes
1answer
62 views

Change some elements at the second level of a list based on some conditions

I need to change some elements at the second level of a list based on some conditions. I have the following list of objects of the same type: ...
10
votes
1answer
208 views

Why does Nearest not support Sqrt?

Bug introduced in 10.0.2 and fixed in 10.3.0 Simple examples with two points nf1=Nearest[{{0, 0}, {Sqrt[2], Sqrt[2]}}] nf1[{0, 0}, {All, 2.1}] gives ...
0
votes
2answers
82 views

Select elements from a list

I need to transform millisecond data of trades of a certain stock to (approximately) minute data. The data is of the form ...
1
vote
2answers
113 views

Pick the maximum element of each nested list [closed]

Suppose that I have a list with nested lists, where each nested list contain entries consisting in 3 columns: ...
0
votes
2answers
102 views

“renormalising” a list [closed]

I am looking for the most effective way to solve the following problem: EDITED (for clarification): I have a large table MyTable, say $200$ columns and $10^5$ ...
5
votes
1answer
244 views

How can I add a mesh over this?

How can I add a mesh over the following 3D plot? ...
1
vote
6answers
201 views

A list of alternating interval between its components

How can I create a list of the following numbers in a table automatically? list={3 π/10, 7 π/10, 13 π/10, 17 π/10, 23 π/10, 27 π/10, 33π/10, 37π/10,....} I ...
6
votes
2answers
163 views

Grouping the list of numbers that have common.

I am working on some simple problem. It is like puzzle.. Let's say I have some list input={{1,1},{1,2},{1,3},{2,3},{3,3},{4,4}} Which means 1 can go and back to ...
5
votes
1answer
99 views

Fast 1D BinCounts Alternative

I have lots of data which looks like this example: ...
1
vote
1answer
67 views

Trace and SameTest in Union [closed]

This question is actually two question. First, I feel so stupid that I just don't understand the use of theSameTest option in ...
2
votes
1answer
81 views

Merge two matrices where one may be empty

In a loop, I want to merge two matrices A and B where B is sometime empty. Example: ...
0
votes
1answer
58 views

Indexing a value within a table function

Is what I'm looking to do possible? I know that I can get it to work with a for loop, but a table would make things much neater. What I need to do while calculation the table below is to reset the ...
1
vote
1answer
80 views

Plot column using some list as x values? [closed]

I've got a mathematica notebook that uses RK4 to successively approximate solutions to a vector valued DE. The output is a nested list similar to: ...
0
votes
1answer
47 views

Multiplying columns with factor [duplicate]

If I have a matrix matrix=Table[RandomInteger[],{i,3},{j,3}] And I multiply it with vector={1,3,5} All three rows change ...
0
votes
0answers
48 views

How can I implement arrays which begin with index 0 [duplicate]

I would like to work with arrays (lists) whose first element has index 0 like arrays in C or Python. I cannot use Part[] since <...
3
votes
1answer
60 views

How does levelspec work inside Position?

Please, can you explain the following feature of levelspec inside Position ? This code test=Range[5]; Position[test,x_/;x>2] as expected, gives ...
8
votes
5answers
550 views

How to extract points from a closed curve

OK, let's create a simple closed curve C0 = ContourPlot[x^2/4 + y^2/9 == 1, {x, -5, 5}, {y, -5, 5}]; and let's plot the corresponding points ...
6
votes
3answers
277 views

Reversing components in a list

Suppose I have the following list: Tl={{a, 3, b}, {c, 6, d}, {e, 9, f}, {g, 5, h}} I really want to reverse specific elements of this list such that I get the ...
5
votes
1answer
107 views

How to get a new list by exchanging some elements?

Let's begin with a simple example. Now, we have a list, list0=Range[4]; k1 and k2 are some elements of the list0. If |k1-k2|==2, then the elements k1 and k2 can ...
4
votes
2answers
124 views

Import Data different column length

Lets assume, i have this data.txt file. s1/km t1/h s2/km t2/h 20 1 40 1 40 2 80 2 60 3 I define myself a function ...
2
votes
2answers
68 views

Converting imported data into a list of pairs [closed]

I have data imported like this: ...
1
vote
1answer
118 views

Turning table into association for Classify

I have the following sample data for 20 users. I know their sex, and the response for three yes/no questions. I am trying to building a classifier to guess their response to the third question, based ...
3
votes
2answers
192 views

Consecutive identical integer members of a list

Can you help me to find and count sub-sequences of consecutive, identical integer members of a long list (at least 1000 members)? By sub-sequences I mean runs like ...
5
votes
2answers
74 views

Select from a list using another list of limits

Given a list of values list1 = {2.4, 3.4, 5.9, 1.2, 9.5, 7.5} and a another list containing theoretical maximum values ...
2
votes
1answer
89 views

How does this code work to substract a set A from a set B?

In an answer to a question (as given here: code), the proposed function was to to subtract a set B from a Set A: ...
3
votes
2answers
94 views

How can I filter a permutation list depending of a pattern? [closed]

I've created a permutation list Grid[Permutations[{a, e, q, r, t, u}], Frame -> All] and only want to see rows where the 5th element is a "t". I tried to do ...
4
votes
3answers
237 views

Will the “for” loop not have an effect on something I'm looping over?

My title is probably worded horribly, let me explain what I mean. So I essentially have a list of lists, and I want to go through and mark which list indices have a certain property. This is how I ...
-1
votes
3answers
207 views

What would be a good way to implement index notation?

So I need to calculate a 3x3 rotation operator (basically a matrix). I have an index-notation expression, and I was wondering if with pre-calculated theta, K1, K2, and K3, could Mathematica compute ...
1
vote
1answer
160 views

Simplify the huge determinant product

I try to get the following determinant product result, ...
0
votes
0answers
31 views

What is a proper transaction from nested rules to nested associations? [duplicate]

Considering a list of rules {A -> {A1-> B}} what will be the correct way to come to <|A -> <|A1-> B|>|>?
15
votes
2answers
208 views

Why does Part return empty list for non-existing elements in ;; specification?

When using the ;; specification Part will return empty list for first index above a list dimensions. For example: ...