Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 3056

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

13 votes
Accepted

Replacing values above a threshold with 1

Use Clip: Clip[{0.61975, 10562., 0.43274, 0.15068, 0.13703, 0.057564}, {-Infinity, 1}] {0.61975, 1, 0.43274, 0.15068, 0.13703, 0.057564}
kirma's user avatar
  • 19.1k
5 votes

Pattern matching - comparing two lists

I assume you want to find an exact match, instead of just that individual members of the subset are found in the larger list. This can be quite easily be accomplished with the following: ClearAll[sub …
kirma's user avatar
  • 19.1k
2 votes

How to trim the zeros from the right of a list?

Do you absolutely need a built-in function? At least if performance is not a concern, this is the simplest way to do it: {0,1,0,0,2,0,0} /. {x___, 0 ..} :> {x} {0, 1, 0, 0, 2} This can be writ …
kirma's user avatar
  • 19.1k
3 votes

Combining two lists taking all possible combinations into account

updatedm = Flatten /@ Tuples[{m, l}] List-of-lists variant of Tuples does this directly, you just need to flatten (or Apply@Append) entries of l for each element of output to achieve your intended r …
kirma's user avatar
  • 19.1k
7 votes

Better way to make a certain list with palindromic sublists

The question is in my opinion more about math than Mathematica and so is my answer (unless the goal is to create these lists through specific constructs), but here it is nonetheless: Table[(1 + x - A …
kirma's user avatar
  • 19.1k
5 votes
Accepted

Isolating sequences from a list based on a formula

Use PatternSequence, Condition (/;) and a form of Repeated that allows matching zero or one times: SeedRandom[6]; With[{alist = RandomInteger[{-2, 2}, 200]}, SequenceReplace[alist, k : {PatternSe …
kirma's user avatar
  • 19.1k
19 votes
6 answers
1k views

A clean way to conceptually extract Parts from a circular list

I quite often run into a situation where I want to treat a list as a circular (repeating) list, and want to take a specific sublist of it, such as... One past the end of the list: Append[#, First@#] …
kirma's user avatar
  • 19.1k
9 votes
7 answers
547 views

Efficient deletion of specific list entries

It is sometimes useful to remove exactly the amount of specific entries on one list from another. Consider: CountingComplement[{1, 2, 1, 3, 1, 3, 4, 5}, {6, 1, 3, 1, 5}] {2, 1, 3, 4} Two 1s a …
kirma's user avatar
  • 19.1k
6 votes

What's fastest way of defining 10^5 down values?

My solution is ugly, but task-specific. It builds a bitmap out of machine-sized integers in imperative fashion and uses Compile. This works reasonably in memory usage for ranges that have at least cou …
kirma's user avatar
  • 19.1k
3 votes
Accepted

Calculate Cumulative Mean and Standard Deviation of a list without FOR loops

Turning my comment into an answer: ClearAll[MapAccumulate]; MapAccumulate[f_, list_List] := f@Take[list, #] & /@ Range@Length@list; Now you can do stuff like this: MapAccumulate[Mean, mylist]
kirma's user avatar
  • 19.1k
12 votes

How to generate all possible orderless partitions of a list according to another list?

It's far from pretty, using pattern matching (OrderlessPatternSequence): ReplaceList[#1, Module[{names = Unique[] & /@ #1, partitions}, partitions = Internal`PartitionRagged[names, #2]; Ac …
kirma's user avatar
  • 19.1k
2 votes

Find duplicates in list of InfiniteLine

RegionEqual, like many region functions, is able to compute symbolic results as long as arguments are fully specified. This allows more efficient constructions of the following kind - where the symbol …
kirma's user avatar
  • 19.1k
1 vote

Random Matrix with criteria

If we ignore random sampling, this is a simple question of Boolean satisfiability: Module[{m, n, greens, matrix, sol}, m = 8; n = 5; greens = 20; matrix = Array[c, {m, n}]; sol = matrix /. …
kirma's user avatar
  • 19.1k
32 votes
Accepted

Can Mathematica put these puzzle pieces together?

Assuming polygons follow the same (clockwise or counterclockwise) vertex order, find all good quality two line segment rigid mappings between polygons without overlap with each other (at least much ov …
kirma's user avatar
  • 19.1k
14 votes
Accepted

Evenly spaced Tick marks for Primes

As people on the comments pointed out this may be a problematic in various ways, but if all y-values of your points are primes, this can be accomplished with ScalingFunctions option. PrimePi is an inv …
kirma's user avatar
  • 19.1k

15 30 50 per page