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 74641

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

9 votes

Pure function of lists

Remove@f f[s_,l_]:= Evaluate@Total[Sign[s] Slot/@Abs@s]& @@@l
Adam's user avatar
  • 4,006
6 votes
4 answers
182 views

Check if list is singleton in sub linear time

A singleton is a list whose elements are equal. Some ways of checking this in Mathematica: {Equal@@#&, 1==Length@Union@#&, MatchQ[#,{x_ ..}]&} I started benchmarking: Table[First@RepeatedTiming[#@ …
Adam's user avatar
  • 4,006
5 votes

How to generate Venn diagram from a universe and 3 random sets?

the 'math' code Remove[universe,a,b,c,onlya,onlyb,onlyc,onlyab,onlybc,onlyca,onlyabc] universe = Range[1, 50]; a = RandomSample[#, RandomInteger@{1, Length@#}]\ &[universe ⋂ Range[3, 30]]; b = Rando …
Adam's user avatar
  • 4,006
5 votes
3 answers
246 views

Thread Matrices, like image channels

The code With[{matA=Partition[Alphabet[],5],matB=Partition[Range@25,5]}, (* matA and matB are 5x5 matrices*) MapThread[List,{matA,matB},2] ] is fairly straightforward. The MapThread part does 'int …
Adam's user avatar
  • 4,006
3 votes

Successive chunking of a list

I'll just answer your first bullet point. Evaluation code: eval[func_]:= ReleaseHold[Hold@func/.{ f -> (TakeLargest[#, UpTo@4] &), list -> {19,4,12,1,17,13,7,14,10,11,6,18,20,15,16,3,8,5,2,9}} ] …
Adam's user avatar
  • 4,006
2 votes

ArrayReshape in an almost rectangular way

Alright I don't know how to make nice looking plots yet but kglr's approach Transpose[{#[[All, {1, 2}]], #[[All, {3, 4}]], #[[All, 5]]}] &@list and lecicr's first approach that calls RandomReal thre …
Adam's user avatar
  • 4,006
2 votes

Counting number of points in fluctuating lines that fall within a circle

Perhaps the cleanest way to find this distribution is with Nearest. I.e. pts=RandomReal[{-10,10},{10000000,2}]; center={1,1}; rad=1; Timing@Length@Nearest[pts,center,{\[Infinity],rad}] (* .08 seconds …
Adam's user avatar
  • 4,006
1 vote
2 answers
99 views

ArrayReshape in an almost rectangular way

I want to make a list of many (say 1000) test instances for a geometry problem. The problem involves two line segments and a point. So I need { (* first line *) (*second line*) (*point*) …
Adam's user avatar
  • 4,006
0 votes

Check if list is singleton in sub linear time

The compeditors: adam0[l_List]:=Equal@@l; adam1[l_List]:=1==Length@Union@l; adam2[l_List]:=MatchQ[l,{x_ ..}]; adam3[l_List]:=If[Null===Do[If[l[[i]]==l[[i+1]],Return@0],{i,Length@l-1}],True,False]; all …
Adam's user avatar
  • 4,006