Hot answers tagged

13

data = {{1, a, x, "one"}, {2, b, y, "two"}, {3, c, z, "three"}}; functions = {f, g, h, m}; Inner[#2[#1] &, data, functions, List] (* Out: {{f[1], g[a], h[x], m["one"]}, {f[2], g[b], h[y], m["two"]}, {f[3], g[c], h[z], m["three"]}} *) With reversing the order of functions and data, to fully harness the functional style without using slots: ...


5

data // Replace[#, {a_, b_, c_, d_} :> {f@a, g@b, h@c, m@d}, 1] &


5

Not quite as nice and concise as the Inner solution, but still worth writing down I think: MapThread[#1@#2 &, {Table[functions, {Length@data}], data}, 2] MapThread[Compose, {Table[functions, {Length@data}], data}, 2] or MapThread[#1@#2 &, {functions, #}] & /@ data MapThread[Compose, {functions, #}] & /@ data or


4

Given: list = {-3., -2.6, -2.2, -1.8, -1.4, -1., -0.6, -0.2, 0.2, 0.6, 1., 1.4, 1.8, 2.2, 2.6, 3.}; {min, max} = {-1.5, 3}; {pos, non} = {50, 700}; I'd just stick with a direct expression of the requirement: Replace[list, x_ /; min < x < max :> If[Positive[x], pos, non], {1}] (* {-3., -2.6, -2.2, -1.8, 700, 700, 700, 700, 50, 50, 50, 50, 50, 50,...


4

Needs["GeneralUtilities`"] MultiMapAt[Transpose[{ConstantArray[All, #], Range@#}]&[Length@functions], functions][data] {{f[1], g[a], h[x], m["one"]}, {f[2], g[b], h[y], m["two"]}, {f[3], g[c], h[z], m["three"]}} Which does the same as (Composition @@ MapThread[MapAt, {functions, {{All, 1}, {All, 2}, {All, 3}, {All, 4}}}])@data


4

data = {{1, a, x, "one"}, {2, b, y, "two"}, {3, c, z, "three"}}; functions = {f, g, h, m}; Late for the party: Transpose[# /@ {##2} & @@@ Transpose @ Prepend[data, functions]]


3

Solution provided by Anton and J.M.: labelstoarguments[expr_, variables_] := With[{ temp = expr /. ((#[idx__Integer] :> # @@ Slot /@ {idx}) & /@ variables) /. ((Subscript[#, idx__Integer] :> Subscript[#, Sequence @@ Slot /@ {idx}]) & /@ variables) }, Function[temp] ] An example usage: labelstoarguments[s[1] + 3 s[2] + k[1,3], {...


3

Note that you have a "." in your original expression, "a dog jumped". instead of , and also I do not know why sat is not there, so I made one up for it. But any way, is this what you wanted? list = {{1, "the dog jumped", "Tues : Wed : Sat"}, {2, "the fox ran", "Mon : Tues : Fri"}, {3, "a dog jumped", "Wed : Mon : Tues"}}; rep = {":" -> "+", "Mon" -&...


3

Maybe this will fit your needs ReplaceAll[ { f[a + 3, b + 3, c + 3], f[x + 3, x + 3, x + 1], f[x + 2, y + 3, x + 1] }, f[p__] :> With[{c = Intersection[p]}, c + f @@ ({p} - c)] (*thanks to J.M.*) ] ] { 3 + f[a, b, c], x + f[3, 3, 1], f[2 + x, 3 + y, 1 + x] } Earlier I overdid it with f[p__] :> With[{c = Plus @@ ...


3

Since the problem is specified without context, here is a very specific solution: expr = f[a + 3, b + 3, c + 3, d + 3, e + 3]; Thread[expr, Plus] /. f[n_ ..] :> n 3 + f[a, b, c, d, e] Leaving aside the curious question of pattern matching raised in the comments here is a baroque approach that should at least be applicable in a number of cases. ...


2

Define your rule as a function: ruleDerF = (# /. Module[{x}, Derivative[n_][f][var_] :> (D[x f[x], {x, n - 1}] /. x -> var) ])& f''[x] // ruleDerF f[x] + x Derivative[1][f][x] FixedPoint[ruleDerF, f''[x]] f[x] + x^2 f[x] FixedPoint[ruleDerF, f''[1]] 2 f[1] (havent tested heavily)


2

expr = -((2 23 (-1 + k^2 JacobiSN[h Ω, k]^4))/ (k^2 JacobiCN[h Ω, k] JacobiDN[h Ω, k] JacobiSN[h Ω, k]^2)); rules = {_JacobiSN -> sn, _JacobiCN -> cn, _JacobiDN -> dn}; expr /. rules


1

Another approach you might find use in: repWithin[expr_, {heads__} | heads_, rules_] := expr /. foo : Alternatives[heads][__] :> (foo /. rules) Now: repWithin[s[1] + s[3] + s[1, 3], s, permreplacements[3][[2]]] (* out= s[1] + s[2] + s[1, 2] *) repWithin[s[1] + 3 s[2] + k[1, 3], {s, k}, permreplacements[3][[4]]] (* out= k[2, 1] + s[2] + 3 s[3] ...



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