penguin77
  • Member for 6 years, 10 months
  • Last seen more than 1 year ago
Collect distributed sums
Accepted answer
2 votes

You may consider this, rl= (a_. Sum[b_. Subscript[x_, i_], {i_, i0_: 1, n_}]) :> Sum[(a b) Subscript[x, i], {i, i0, n}]; exp = Sum[2/9 Subscript[x, i], {i, 1, n}] + 2 Sum[1/9 Subscript[x,...

View answer
Perform operation on part of a table / create a reference
1 votes

You may consider spec = Sequence @@ (Span @@ # & /@ rect); Part[t, spec] or t[[spec]] This would lead to: With[{spec = Sequence @@ (Span @@ # & /@ rect)}, t[[spec]] = Map[f, t[[spec]]...

View answer
SetOptions for CoordinatesToolOptions for DateListPlot?
0 votes

You may consider this: DateListPlot[{{1, 1, 2, 3, 5, 8, 11}, {5, 8, 9, 6, 2, 4, 7}}, {2013,1,1}, Joined -> True, CoordinatesToolOptions -> {"DisplayFunction" -> (DateString@First@# &)}...

View answer
Indexed Map Thread
7 votes

You may consider this MapIndexed[Times, #] & /@ {{a, b, c}, {e, f, g}} // Plus @@ # & (* {{a + e}, {2 b + 2 f}, {3 c + 3 g}} *) MapIndexed applies a function (in your example Times to ...

View answer
Strange behaviour of Append
Accepted answer
2 votes

Append has no side effect You may try AppendTo a = {x^2 + y^2 == 1}; AppendTo[a, x + y == 0] Solve[a, {x, y}] resulting in (* {{x -> -(1/Sqrt[2]), y -> 1/Sqrt[2]}, {x -> 1/Sqrt[2], ...

View answer
Make a program that does union of two lists
3 votes

Instead of using a for loop, you may consider Union straight away: Union[RandomInteger[10, 3], RandomInteger[10, 3]] (*{0, 4, 6, 9, 10} Obviously result will different for each run *)

View answer
Customizing X-axis label for groups of 7 (weeks)
4 votes

Creating a data set dset with date values for the period of 5 months starting on a Sunday associated with random integers ( DayName @ {2015, 04, 12} (* Sunday*)). dset = DateRange[{2015, 04, 12}, ...

View answer
How to plot a table of the results of findmaximum?
1 votes

That's like a breeze: result = {{0.148148, {t -> 0.333333}}, {0.204148, {t -> 0.384677}}} Flatten /@ result /. x_Rule :> x[[2]] // ListLinePlot PS: Because there are only 2 points better ...

View answer
Folding 3-variate function with 2 iterator
Accepted answer
4 votes

Here we go using FoldList list = Array[{Subscript[a, #], Subscript[b, #]} &, {3, 1}] // Flatten /@ # & (* or Flatten[#,1]& doing the same, but faster *) FoldList[f[#, Sequence @@ #...

View answer
Do TakeWhile and LengthWhile work with Greater?
Accepted answer
3 votes

I trust, you have figured out the response to your "why" question by reading the comments. For your convenience here some very common ways for selecting elements from a list. Cases[{1, 2, 3, 4, 5}, ...

View answer
Define a matrix depending on variable in Mathematica
Accepted answer
3 votes

Do you mean this ? n = 5; getA[kappa_] := Table[2*Cos[(2*π/n)*(Abs @(i - j))*kappa], {i, 0, n-1}, {j, 0, n-1}] getA[3] //MatrixForm You may post the expected result from your Python code in ...

View answer
Limit the number of processors used by ParallelTable?
7 votes

To demonstrate evaluation in parallel computing on different number of kernels 1)Default list of kernels run for parallel computing `$ConfiguredKernels` (*("<<`1` local kernels>>", ...

View answer
calculating subsets of a matrix (L=40X40)
1 votes

I would suggest to take out of Do any evaluation that need to be done only once and make sure to clear variables between successive runs. Clear[L, LL, k, config] L = 50; LL = L!; Do[t = LL/(k! (L -...

View answer
How to stop a Dynamic[] in one notebook from hurting performance in another?
3 votes

You may consider moving the variables used for the dynamic clock into a dedicated context Dynamic[{clock`d, clock`h, clock`m, clock`s} = List @@ DateDifference[Now, DateObject[{2015, 5, 18}],...

View answer
mathematica use too much memory to Import large dat file
Accepted answer
3 votes

M9 under Windows 7, Intel Core i7 970. 24 GB RAM, Import without any problem. Alternatively you can read the file as a stream. str = OpenRead["z:\\temp\\omni_m_all_years.dat"] ReadList[str, Record]...

View answer
How to simplify and shorten pattern code?
Accepted answer
2 votes

You may consider this to produce same result as your code: n = 15; s = 11; m = 3; ip = IntegerPartitions[n, {m}]; Select[ip, Max @@ # < s && DuplicateFreeQ@# &]

View answer
How to delete Missing["NotAvailable"] from list of rules?
3 votes

Less elegant than DeleteCases, however an alternative: exp = {First -> {a -> "aaaa", b -> "bbbb"}, Second -> {c -> "cccc", d -> "dddd", e -> Missing["NotAvailable"], f -&...

View answer
How to create a recursive TreeGraph
Accepted answer
2 votes

If your are looking for a Binary tree than this may work for you: fnBTree[n_] := CompleteKaryTree[Sequence @@ # , VertexLabels -> "Name"] & /@ Join[{{1, 1}, {2, 1}}, Table[{i + 1, 2}, ...

View answer
Apply an accumulative function to each column of a dataset
3 votes

Illustrating Rasher's suggestions for your convenience with some data set. Just create anything for the sake to demonstrate counting: dset = ElementData[#, "SoundSpeed"] & /@ ElementData[] // ...

View answer
ContourPlot: format numbers in contour labels and legend
3 votes

Replace PlotLegends-> Automatic with Barlegend combined with option LegendFunction PlotLegends -> BarLegend[Automatic, LegendFunction -> (ScientificForm[# // N] &)]]

View answer
Why is a symbol still found after changing its context?
0 votes

No erratic behavior on my computer M9. However a simple workaround could be considered that achieves its purpose. Workaround for moving a symbol from one context to another can be achieved by: For ...

View answer
What are the cool kids talking about when they use ##&[]?
8 votes

I believe it is important to get a fundamental understanding of what Pure Functions are that goes beyond the understanding using of a syntax. Hereafter an non-exhaustif summary of a few key ...

View answer
Function for importing and plotting data from excel spreadsheet
Accepted answer
1 votes

In your first line of your code the variable a is assigned the string ["/Users/pedrofonsecazuccolo...." and then trying to use the Part function that is a[[1,Range[1,19],2]] which indeed is a wrong ...

View answer
What is the meaning of two square brackets in function definition?
2 votes

Example 3 is very different from example 1 and 2. Example 2 is a function with 4 arguments whereas example 3 has two arguments, first argument is a list with three elements{a_,b_,c_} and 2nd ...

View answer
interactively replace pixel value
Accepted answer
3 votes

One way of getting this to work is by using the Locator as a Control of Manipulate. For the convenience of easier spotting the replaced pixel I have cropped and magnified the image. image = ...

View answer
Grid versus GraphicsGrid use cases?
4 votes

uuhahh, there is an important big difference. Grid returns a Grid object whereas GraphicsGrid returns an Image. Therefore you will be able to apply all Image functions to GraphicsGrid as a whole, ...

View answer
How to show several plots with ListAnimate
Accepted answer
1 votes

Here the code using ListAnimate data1 = {{{0, 2}, {1, 4}}, {{0, 2}, {1, 8}}}; data2 = {{{0, 3}, {3, 4}}, {{1, 5}}}; Show /@ Transpose @ (Table[ ListLinePlot[#[[n]], PlotRange -> {0, ...

View answer
Auto Execute Notebook on Open
0 votes

Yes you can do it using the option IntializationCell, moreover there are complementary options for controlling its behavior. Here is the documentation on how to achieve it https://reference.wolfram....

View answer
What is the URL of the site used by ExampleData?
0 votes

Easy work around without needing to figure out URL Remove all symbols used for retrieving example data from the Context Remove["DataPaclets`ExampleDataDump`*"] This will permit you still to ...

View answer
Clicking on "Show all results" in a W|A pod hangs Mathematica
1 votes

Try WolframAlpha["Forest Gump", "FullOutput"] runs about 1 sec. on my computer. Hint: Make sure you have fast Internet connection. Here an extract of screenshot of result

View answer