Tag Info

New answers tagged

4

If Table is part of your actual operation you will be served by learning Array: Array[#, {2, 2}] & /@ {Plus, Subtract, Times, Divide} { {{2, 3}, {3, 4}}, {{0, -1}, {1, 0}}, {{1, 2}, {2, 4}}, {{1, 1/2}, {2, 1}} }


10

This is really a natural fit for Outer: t = Table[{i, j}, {i, 1, 2}, {j, 1, 2}]; Outer[Apply, {Plus, Subtract, Times, Divide}, t, 2] (* ==> {{{2, 3}, {3, 4}}, {{0, -1}, {1, 0}}, {{1, 2}, {2, 4}}, {{1, 1/2}, {2, 1}}} *)


3

An alternative using Replace to do this: mytable = Table[{i, j}, {i, 1, 2}, {j, 1, 2}]; Replace[mytable, List[a_, b_] -> #[a, b], {-2}] & /@ {Plus, Subtract, Times, Divide} {{{2, 3}, {3, 4}}, {{0, -1}, {1, 0}}, {{1, 2}, {2, 4}}, {{1, 1/2}, {2, 1}}}


7

You very nearly had it. What you need, instead of Map[], is Apply[]. This can then be combined with Map[], like so: mat = Table[{i, j}, {i, 2}, {j, 2}]; Apply[#, mat, {2}] & /@ {Plus, Subtract, Times, Divide}


5

You might just map the Maps ops = {plus, subtract, times, divide} = Function[op, Map[op[#[[1]], #[[2]]] &, Table[{i, j}, {i, 1, 2}, {j, 1, 2}], {2}]] /@ {Plus, Subtract, Times, Divide} {{{2, 3}, {3, 4}}, {{0, -1}, {1, 0}}, {{1, 2}, {2, 4}}, {{1, 1/2}, {2, 1}}}


4

You need to set a Hold attribute for your function, as @N.J.Evans mentioned as well. Also, instead of using Trace to obtain the symbol name, try using SymbolName instead: Clear[exportTable] SetAttributes[exportTable, HoldFirst] exportTable[t_] := Export[SymbolName[Unevaluated[t]] <> ".dat", t] exportTable[table1] You can then re-import your table ...


4

This should be much faster than using a loop or mapping: rng = 100000; min = 0; max = 10000; k := 0.5; offsets = RandomInteger[{1, 10}, rng]; randomA = RandomReal[{min, max}, rng]; randomB = RandomReal[{min, max}, rng]; effect = xEffect = Range@rng; us = UnitStep[xEffect - offsets - 1]; nr = Pick[Range@Length@effect, us, 0]; nr2 = ...


2

Like this: computeEffect[xEffect_] := With[{offset = RandomInteger[{1, 10}]}, If[xEffect - offset < 1, RandomValue, randomA[[xEffect - offset]] + k randomB[[xEffect - offset]] ] ] effect = computeEffect /@ Range[1000]; Or effectLength = 1000; diffs = Range[effectLength] - RandomInteger[{1, 10}, effectLength]; computeEffect2[diff_] := ...


2

All done by Morphological Components clusteringb[config_] := Module[{output, cm, cindices, csizes}, output = MorphologicalComponents[Image@Abs@config, CornerNeighbors -> False]; cm = ComponentMeasurements[ output, {"Label", "Mask", "Count"}][[All, 2]]; {cindices, csizes} = Transpose[{{#1, #2["NonzeroPositions"]}, {#1, #3}} & @@@ cm]; ...


5

March - this is not a complete answer, but instead addresses the gathering of indices since that seems to be important. Here's a comparison of some methods, tested only on my cigar-lounge netbook so caveat lector. OP - Virgil's original (position based), Virgil - Virgil's adaptation of my first comment, CMT. 2/3 - my second and third comments (gathered ...


7

Built-in option This sidesteps most of your code, so it might not be what you are looking for, but I believe your goal can be achieved with Mathematica's built-in image processing capability, specifically: MorphologicalComponents! Define a new clustering function clustering1[config_] := Module[{output, csizes, cindices}, output = ...


2

As suggested by @MichaelE2 in the comments, I ended up using the composition operator @*. My final code looks like: Grid @* Join @@ {Keys@Take[#, 1], Values@#}& @ lst1



Top 50 recent answers are included