Linked Questions

6 votes
4 answers
514 views

Find the identical rows in a matrix [duplicate]

Suppose I have the following matrix: ...
user avatar
  • 1,039
1 vote
4 answers
316 views

Using Select in Subsets [duplicate]

I have a list: list = {{7, 6, 14, 14, 4}, {4, 9, 8, 11, 14}, {20, 12, 12, 11, 3}, {7, 4, 11, 7, 20}, {2, 13, 17, 11, 19}} I did a test to identify where ...
user avatar
5 votes
2 answers
149 views

Position of first element in list which is repeated [duplicate]

I have the list t1 = {{-1, 0}, {-2, 0}, {-3, 0}, {0, 0}, {-2, 0}, {1, 1}} How do I find the position where an element repeats? In this case it would be element <...
user avatar
  • 2,020
584 votes
19 answers
148k 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 ...
76 votes
8 answers
6k views

Partitioning with varying partition size

How can I partition a list into partitions whose sizes vary? The length of the $k$'th partition is a function $f(k)$. For example: if $l = \{1, 2, 3, 4, 5, 6\}$ and $f(k) = k$. Then the partitioning ...
user avatar
  • 7,337
22 votes
13 answers
4k views

How to get list of duplicates when using DeleteDuplicates?

This might be easy, but can't find a way to use DeleteDuplicates to get also list of the actual duplicates. Example: ...
user avatar
  • 108k
12 votes
4 answers
7k views

Delete duplicate elements from a list

If a list contains duplicate elements, for example list = {a, 1, 5, 3, 5, x^2, x^2}, how can the duplicate elements be removed? The result would be ...
user avatar
  • 7,337
23 votes
6 answers
4k views

Looking for a way to insert multiple elements into multiple positions simultaneously in a list

I would like to take the following data: insertValues = {r, x}; insertPositions = {{1}, {5}}; originalList = {a, b, c, d, e, f, g}; and generate output that ...
user avatar
  • 2,024
12 votes
11 answers
526 views

Positions of elements in the initial flattened list in a split list

Say, we have a list: m1 = {2, 2, 7, 0, 7, 7, 2, 2, 2} It can be split easily: ...
user avatar
  • 4,735
23 votes
7 answers
2k views

How do I obtain an intersection of two or more list of lists conditioned on the first element of each sub-list?

Given two lists like list1 = {{1, 1}, {2, 4}, {3, 9}, {4, 16}}; list2 = {{2, 6}, {3, 9}, {4, 12}, {5, 15}}; I would like to produce an output like ...
user avatar
47 votes
3 answers
1k views

Why is the new PositionIndex horribly slow?

This issue has largely been mitigated in 10.0.1. New timings for the final test below are: ...
user avatar
  • 264k
26 votes
5 answers
961 views

Partitioning a list when the cumulative sum exceeds 1

I have a long list of say 1 million Uniform(0,1) random numbers, such as: dat = {0.71, 0.685, 0.16, 0.82, 0.73, 0.44, 0.89, 0.02, 0.47, 0.65} I want to ...
user avatar
  • 8,441
17 votes
6 answers
592 views

Pick elements from list "separately"

I have the following list I want to pick elements from: mylist = {1, 5, 7, 3, 4, 7, 2, 9, 9, 1, 10, 12, 2, 64, 34, 64} I have another list with 0's and 1's which ...
user avatar
  • 2,703
19 votes
5 answers
1k views

Easiest/most efficient way to delete duplicates from one list at the positions of another?

This question is somewhat related to How to efficiently find positions of duplicates? , although I'm interested in something a little bit simpler since I'm not really interested in a list of all the ...
user avatar
  • 191
13 votes
5 answers
3k views

Match opening and closing parentheses?

Suppose I have a List of the form: lst={"(", "(", "(", ")", "(", ")", ")", ")"} By running ...
user avatar
  • 10.7k

15 30 50 per page