New answers tagged

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,...


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)


0

As far as I understood from your answers to comments you like KronekerDelta in the stiffness tensor, but not in the stress tensor. You can do as follows: stiff[i_, j_, k_, l_] := L KroneckerDelta[i, j] KroneckerDelta[k, l] + \[Mu] (KroneckerDelta[i, k] KroneckerDelta[j, l] + KroneckerDelta[i, l] KroneckerDelta[j, k]) vg = Array[v, {3, 3}]; vg //...


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


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]]


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

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


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] &


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" -&...


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] ...


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

fun:=(1-Unitize[#])*Range[Length@#]+#& Usage fun/@CombiningCyclesCase2 {{1,2,3,4,5},{1,2,4,3,5},{1,2,4,5,3},{3,2,1,4,5},{3,2,1,5,4},{3,2,4,1,5},{3,4,1,2,5},{3,2,4,5,1},{3,5,4,1,2}}


6

If your lists are large (and rectangular as your example), this s/b considerably faster than existing answers: fix=With[{d=Dimensions@#},#+BitXor[1,Unitize@#]*ConstantArray[Range@d[[2]],d[[1]]]]&; or simpler and similar speed: fix2=With[{rx = Range@Length@#[[1]]}, (# + BitXor[1, Unitize[#]]*rx) & /@ #] &;



Top 50 recent answers are included