Linked Questions

604 votes
19 answers
158k views

Where can I find examples of good Mathematica programming practice?

I consider myself a pretty good Mathematica programmer, but I'm always looking out for ways to either improve my way of doing things in Mathematica, or to see if there's something nifty that I haven't ...
78 votes
9 answers
12k views

How to efficiently find positions of duplicates?

Is there an efficient way to find the positions of the duplicates in a list? I would like the positions grouped according to duplicated elements. For instance, given ...
Michael E2's user avatar
  • 245k
14 votes
8 answers
2k views

Given an ordered set S, find the points in S corresponding to another list

Given a sorted list of numbers $S$, I want to create a function that accepts a list of numbers $L$ and for each number $l \in L$ it returns the index of the largest number $s \in S$ such that $s<l$....
Carl Woll's user avatar
  • 132k
10 votes
7 answers
359 views

How to insert elements at different locations of a given list

Say a list is given as list = {a, b, c, d, r, m, n}; Suppose I want to insert 2 and 3 at position 3 and 7, respectively. ...
Soumyajit Roy's user avatar
13 votes
5 answers
290 views

Inserting some zeros in a list by a rule of positions

I have a list: mainlist={0.23, 0.34, 0.8, 0.0, -0.2, 0.4, -0.1}; I have to extend the above list to another one finalresult ...
Inzo Babaria's user avatar
  • 1,533
11 votes
4 answers
2k views

How to insert / merge a list into another list?

Background: I am working on a 2D geometry algorithm where I need to insert a list of 2D points into another list of 2D points. Somewhat to my surprise I found no Mathematica function capable of doing ...
nilo de roock's user avatar
11 votes
5 answers
2k views

Relational joining of tables

A common thing to want to do with data is to combine it (at least I thought this was a common thing). In SQL there is the idea of table joins "select id,v1,v2 from A,B where A.id=B.id" kind of thing. ...
user avatar
5 votes
6 answers
276 views

Pairing headers with each subsequent entry in a flattened list

I have a list containing headers of the form a-*; each followed by a variable number of entries: ...
Suite401's user avatar
  • 5,025
8 votes
4 answers
1k views

Efficient method for Inserting arrays into arrays

This is strongly related to the following Questions: Looking for a way to insert multiple elements into multiple positions simultaneously in a list Building matrices by attaching vectors (columns) ...
Pam's user avatar
  • 1,867
3 votes
5 answers
1k views

Randomly selecting and reinserting a subset of elements in a list

This question is similar to my other question: How do I randomly select 'k' positions in a list and shuffle their respective elements without effecting the other elements? Imagine first a ...
S22's user avatar
  • 115
1 vote
3 answers
347 views

professionalize/optimize my code that calls a function

I have the following construction, which defines a function that I subsequently call in a loop multiple times. I use this very often, but I have never looked into if there is a more professional way ...
BillyJean's user avatar
  • 1,283
3 votes
3 answers
413 views

How to double elements of a list given by their positions

Given that I have a list $\{P_0,P_1,P_2,\cdots,P_7\}$, where, $P_i$ is a real number or a list like {x,y}/{x,y,z}. Now I would like to double some elements ...
xyz's user avatar
  • 655
1 vote
2 answers
355 views

Insert at specific resulting positions?

I have an initial list: list0 = {1,2,3,4,5}; and I want to insert {a,x} at specific positions ...
a06e's user avatar
  • 11.5k
1 vote
1 answer
58 views

How to avoid multiple copies of a list when mapping a pure function to it?

Given this code: mylist = Tuples[{a, e}, 2]; Insert[mylist, 1, {#, 3}] & /@ Range[2] The output is this: {{{a, a, 1}, {a, e}, {e, a}, {e, e}}, {{a, a}, {a,...
GambitSquared's user avatar