# Search Results

Results tagged with Search options user 280
22 results

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

It looks like what you wish is called Dilation and Erosion :) Dilation[list, {1, 1, 1}] Erosion[list, {1, 1, 1}, Padding -> 0] {0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, …
answered Mar 26 '17 by Alexey Popkov
Citing the Documentation (emphasis is mine): Nothing is removed as part of the standard evaluation process. It is not removed in expressions that are held or inactive. So it should be removed …
answered Aug 15 '16 by Alexey Popkov
I think the most straightforward way is to use Switch and MapIndexed: colorF[l_, {i_}] := Switch[i, 4 | 9 | 2, Style[l, Red], 3 | 5 | 7, Style[l, Green], 8 | 1 | 6, Style[l, Blue], _, l …
answered Sep 1 '13 by Alexey Popkov
I was expecting mathematica to also be able to access the fields in place without writing a new list In-place modification approach: list = {{a1, {b1, c1}}, {a2, {b2, c2}}, {a3, {b3, c3}}}; list …
answered Jun 23 '18 by Alexey Popkov
A timing comparison for all suggested methods which do not sort (Mathematica 11.0.0): f1[{list_, labels_}] := Extract[list, Position[labels, #]] & /@ DeleteDuplicates@labels f2[{list_, labels_}] := …
answered Feb 12 '17 by Alexey Popkov
Straightforward Splitting approach: l = {{"a",}, {2010, 0}, {2011, 10}, {2012, 27}, {"b",}, {2011, 11}, {2012, 66}, {"c",}, {2010, 19}, {2011, 20}, {2012,}}; Flatten /@ Flatten[Thread[{#[[1, …
answered Nov 6 '14 by Alexey Popkov
Here is my trial: The levelspec {2, -2} means "all subexpressions which can be specified by at least 2 indices down to subexpressions with depth not lesser than 2". In the expression a[1, b[2, c[3]] …
answered May 30 '15 by Alexey Popkov
Some additional alternatives: TextString[Row@#] &@{0, 0, 1, 3} "0013" TextString[#, ListFormat -> {"", "", ""}] &@{0, 0, 1, 3} "0013" StringDrop[ToString@FromDigits[Prepend[#, 1]], 1] &@{ …
answered Feb 22 by Alexey Popkov
This problem can be solved very efficiently using string patterns: str = ToString[FromDigits@RealDigits[99/700, 10, 24][[1]]]; AbsoluteTiming[StringReplace[str, StartOfString ~~ pre : Shortest[D …
answered Jul 31 '16 by Alexey Popkov
Here is another approach based on excellent Coolwater's idea: f[x_] = x; s = NDSolve[{g[0] == 0, g'[x] == f[x]}, g, {x, 0, 1}][[1, 1, 2]]; ListLinePlot[Transpose[{Flatten@#["Grid"], #["ValuesOnGrid"] …
answered Feb 3 '14 by Alexey Popkov
Is there some workaround to get stable sorting result with SortBy? Yes, just wrap the second argument by List: SortBy[data, {#[[2]] &}][[;; , -1]][[-4 ;; -1]] {2.15906, 1.86386, 4.42245, 1.93 …
answered Mar 4 by Alexey Popkov
MapIndexed[Print[Row[{First@#2, #1}, ","]] &, {2, 5, 7}]; 1,2 2,5 3,7 Or simpler: MapIndexed[Print[First@#2, ",", #1] &, {2, 5, 7}] 1,2 2,5 3,7
answered Aug 20 '14 by Alexey Popkov
One way is to specify explicitly how many levels of empty Lists you wish to remove, for example: ClearAll[nothing] nothing /: List[nothing[0] ..] := {}; nothing /: List[nothing[i_Integer] ..] := noth …
answered Mar 17 '17 by Alexey Popkov
If it is known that all the elements are Real, the solution becomes pretty straightforward: l1/.{x_Real}:>{x,0} bigList/.{x_Real}:>{x,0} More general solution is to Replace at level {-2}: Replace[ …
answered Apr 13 '14 by Alexey Popkov
In addition to Mr.Wizard's answer here is a collection of other possibilities: data1 = {1, 1}; data2 = {2, 2}; datalist := {data1, data2}; ToString /@ Map[HoldForm, OwnValues[datalist], {3}][[1, 2]] …
answered Mar 13 '17 by Alexey Popkov

15 30 50 per page