# Search Results

Results tagged with Search options user 5
205 results

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

If you're going to do several lookups repeatedly in a single set, using Associations in version 10 is orders of magnitude faster than BinarySearch. You can try it out if you have Mathematica 10 for Ra …
answered Feb 5 '14 by rm -rf
If you wish to get rid of the {}, then Mike's answer using DeleteCases works in this particular case, but will fail in general, because it will not remove {} that's nested deeper (such as {{}}). Using …
answered Jul 28 '12 by rm -rf
Here's a straightforward way using Cases: list = {{1, 2}, {2, 2}, {3, 1}, {4, 1}, {2, 4}}; (* example list *) With[{min = Min@#[[All, 2]]}, Cases[#, {x_, min} :> x]] &@list (* {3, 4} *) You can als …
answered Sep 3 '12 by rm -rf
It's a floating point issue. The article "What every computer scientist should know about floating point arithmetic" by David Goldberg, is a very good introduction to the topic. In your case, look at …
answered Nov 5 '12 by rm -rf
You can create your triangular table in a far simpler manner as follows: Table[{i, j}, {i, 10}, {j, i + 1, 10}] (* { {{1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {1, 7}, {1, 8}, {1, 9}, {1, 10}}, {{2, …
answered Aug 27 '12 by rm -rf
Here's a direct list-manipulation approach using a variation of Heike's answer for combining subsets with similar terms: Cases[list1, {___, Alternatives @@ #, ___}, 2] & /@ list2 //. x_ :> Union …
answered Mar 5 '14 by rm -rf
The simplest solution would be: #[[Ordering[#, -1]]] &@ tuples
answered Oct 9 '12 by rm -rf
You could just do: f[list__] := Plus[list]/Length@{list} or simpler, using the built-in Mean: f[list__] := Mean[{list}] Using this with your example: f[list1, list2, list3] (* {{0, 4/3}, {0.1, …
answered Sep 18 '12 by rm -rf
One can use MapIndexed to access the next (or previous or any arbitrary offset) element of the currently mapped element. However, you also need to make checks so that you don't index it beyond its bou …
answered Oct 22 '13 by rm -rf
You can use rules to replace rules! Here's an example: {x -> 1, y -> 2, z -> 2} /. HoldPattern[z -> _] :> (z -> 3) (* {x -> 1, y -> 2, z -> 3} *) Now when there isn't a rule involving z and you wan …
answered May 23 '12 by rm -rf
In version 10, the GeneralUtilities context provides a MapIf function that does exactly this: <<GeneralUtilities` MapIf[f, EvenQ, Range@10] (* {1, f[2], 3, f[4], 5, f[6], 7, f[8], 9, f[10]} *) As w …
answered Jul 15 '14 by rm -rf
Here's another one, for fun: lst = {3, 5.6, 8.19, 2, 5.6, 4, 3, 8.5, 4.137, 7., 1.165}; Pick[lst, Mod[lst, 1], 0] (* {3, 2, 4, 3} *)
answered Apr 14 '13 by rm -rf
Since Yves beat me narrowly to my first solution, here's another one using Select: Select[list1, FreeQ[list2, #] &] Out[2]= {b, a, d} This does not sort your result. You can also use Complement, …
answered Feb 4 '12 by rm -rf
I'll join in with my own version: splitList[list_] := Pick[list, IntegerDigits[1/6 (-3 - (-1)^#1 + 2^(2 + #1)) &@Length@list, 2], #] & /@ {1, 0} splitList[{a, b, c, d, e, f, g}] (* {{a, c, e, g …
answered Mar 16 '13 by rm -rf
Leonid's answer is very straightforward and I doubt it can be beat. Nevertheless, here's another approach using pattern matching and rule replacements to get the same result: consecutiveValues[l_List …
answered Jun 11 '12 by rm -rf

15 30 50 per page