Linked Questions

526
votes
19answers
130k 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 ...
61
votes
8answers
8k 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 ...
13
votes
8answers
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$....
10
votes
5answers
1k 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. ...
8
votes
3answers
702 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 ...
13
votes
2answers
249 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 ...
6
votes
4answers
677 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) ...
3
votes
5answers
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 ...
8
votes
3answers
175 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. ...
3
votes
2answers
221 views

Rearranging elements of a list

I have a list: oldList = {"a-1", "b", "c", "a-2", "d", "e", "f", "a-3", "w"} and would like to get the following list: ...
1
vote
3answers
301 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 ...
3
votes
3answers
381 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 ...
1
vote
2answers
164 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 ...
1
vote
1answer
53 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,...