Hot answers tagged

10

ClearAll[makeOuterable] SetAttributes[makeOuterable, HoldFirst] makeOuterable[f_] := Distribute[f@##, List] & Examples: Operate[makeOuterable, f[3, {1, 2}, 5]] {f[3, 1, 5], f[3, 2, 5]} makeOuterable[h][3, {1, 2}, 5] {h[3, 1, 5], h[3, 2, 5]} makeOuterable[h][{1, 2}, {3}] {h[1, 3], h[2, 3]} makeOuterable[h][{1, 2}, {3, 4}] {h[1, 3], h[1, 4], h[2, 3]...


9

Permute exists for reordering lists. Permute[list, Cycles[{{1, 4}, {2, 5}, {3, 6}}]] This swaps entries $1 \leftrightarrow 4$, $2 \leftrightarrow 5$ and $3 \leftrightarrow 6$. The necessary permutation can be found using FindPermutation: FindPermutation[Range@9, {4, 5, 6, 1, 2, 3, 7, 8, 9}] Cycles[{{1, 4}, {2, 5}, {3, 6}}]


8

Somehow Outerable ought to conform to the syntax of Outer. The following does it for the form f[list1, list2,...]: ClearAll[outerify]; SetAttributes[outerify, HoldAll]; outerify[def : Verbatim[SetDelayed][f_[a___], body_]] := ( f[args__List] := Outer[f, args]; def ); However, on the basis of the examples, the OP seems to desire a combination of ...


7

At least shorter: Flatten@Partition[list, 3][[{2, 1, 3}]]


7

SequenceCases[data, {a : {_, _}, b : {_} ..} :> (Sequence @@ ({a[[1]], #} & /@ Flatten[{b}]))] {{0.35, -0.0700506}, {0.35, -1.04149}, {0.52, -0.0100506}, {0.52, -1.02149}, {0.52, 0.593423}, {0.75, 0.0700506}, {0.75, 1.04149}, {0.75, -0.193423}, {0.75, -0.834902}} Alternatively, Split and post-process: Join @@ Map[Thread[{First @ #, Rest @ #}] &...


6

Dataset @ GroupBy[SortBy[First] @ dataset, First -> (#[[{3, 5}]] &), AssociationThread[{"column 3", "column 5"}, Total @ #] &] Dataset @ Values @ GroupBy[SortBy[First] @ dataset, First -> (#[[{1, 3, 5}]] &), AssociationThread[{"Region", "column 3", "column 5"}, Prepend[Total[...


6

The JSON dataset is imported as a list of rules: { {"dateTime" -> "07/07/14 00:00:00", "value" -> "1440"}, {"dateTime" -> "07/08/14 00:00:00", "value" -> "1128"}, ... } So take the second part of each Rule for each point to give string pairs. Then use DateObject ...


5

Id suggest using TakeList TakeList[ist, {{4, 6}, 3, All}] TakeList[ist, {{4, 6}, {1, 3}, {1, 3}}] The indices need to be relative to those elements that are not yet taken. If you have absolute indices given: ist = Range[20]; parts = {{5, 6}, {9, 13}, {1, 4}, {19, 20}, {14, 18}}; Catenate[ist[[# ;; #2]] & @@@ parts]


5

This answer is inspired from the answer given by kglr in your other question: data = {{-1, 2}, {0, 3}, {6, 6}, {1}, {-5, 1}, {0, 0}, {3}, {-3, 3}, {1, 2}, {1}, {0, -1}, {2, 2}, {7}, {5, 5}, {2, 2}, {3, -3}, {4, -4}, {2, -2}, {7}}; First split them: SequenceCases[data, {a : {_, _} .., {b_}} :> b -> Sequence[a]] (*Out: {1 -> Sequence[{-1, ...


3

The scaling of your data1is very poor( x-values O[10^-10])! Logarithmization (y==b x^-a-> Log[y]==Log[b]-a Log[x] helps to find a numerical solution: logxlogy = Map[{Log[#[[1]]], Log[#[[2]]]} &, data1]; fit = FindFit[logxlogy, {logb - a logx}, {a, logb}, logx,Method -> "NMinimize"] Show[ListPlot[data1], Plot[Evaluate[b x^-a /. {b -> ...


3

If you include a list of time series as first argument of DateListPlot you will get a plot with multiple curves. Here is an example where I plot "TTM" and "Quarterly" of the given company in the same plot. For clarity, I first create the time series separately and subsequently feed them to DateListPlot: ds1 = Entity["Company", &...


3

split = Split[data, Length @ # != 1 &]; Column @ split You can use GroupBy to get an Association with singleton elements in data used as keys: grouped = GroupBy[split, First @* Last -> Most] <|1 -> {{{-1, 2}, {0, 3}, {6, 6}}, {{-3, 3}, {1, 2}}}, 3 -> {{{-5, 1}, {0, 0}}}, 7 -> {{{0, -1}, {2, 2}}, {{5, 5}, {2, 2}, {3, -3}, {4, -4}, {...


2

There are some inconsistencies between the code you show (which doesn't run) and the results you obtained. First, your model function in FindFit is currently missing the parameter a. Second, your data should include the temperature values, i.e. it should be built up as a list of pairs. Finally, as a rule of thumb use := (SetDelayed) to define functions, and =...


1

Construct an interpolating function from list1 and evaluate it at x values of list2: iF = Interpolation[list1, "ExtrapolationHandler" -> {Automatic, "WarningMessage" -> False}]; interpolatedlst1 = {#, iF@#} & /@ list2[[All, 1]] {{1.3, 2.3}, {3.2, 4.2}, {5.4, 6.4}, {7.1, 8.1}, {9.5, 10.5}, {11.6, 12.6}, {12.7, 13.7}} ...


1

Define UpValues for mkOuterable as ClearAll[mkOuterable] mkOuterable /: Outer[mkOuterable[f_], a__] := Outer[f, ##] & @@ Replace[{a}, x_?AtomQ :> {x}, 1, Heads -> False] and wrap the first argument of Outer with mkOuterable. Examples: Outer[mkOuterable@u, x, {1, 2}, {a, b}] {{{u[x, 1, a], u[x, 1, b]}, {u[x, 2, a], u[x, 2, b]}}} Outer[...


1

ClearAll[outeR] outeR[f_] := Outer[f, ##] & @@ Replace[{##}, x_?AtomQ :> {x}, 1, Heads -> False] &; Examples: outeR[h][3, {1, 2}] {{h[3, 1], h[3, 2]}} outeR[h][{1, 2}, 3] {{h[1, 3]}, {h[2, 3]}} outeR[h][{1, 2}, x, {a, b}] {{{h[1, x, a], h[1, x, b]}}, {{h[2, x, a], h[2, x, b]}}} outeR[h][a, {1, 2}, x] {{{h[a, 1, x]}, {h[a, 2, x]}}} ...


Only top voted, non community-wiki answers of a minimum length are eligible