# Tag Info

### Why does Replace function not work the first time I try it?

The problem is that the expression doesn't have g[x]/x just isolated from Cos[x]: ...
• 24k

### Why does Replace function not work the first time I try it?

Three errors: Execute cells separately if you refer its result. Use :> instead of -> to avoid evaluation of rules already at input time. Don't use %, it was created for the math.exe text input. ...
• 3,947

### Replace items of list except items that are member of another list

a = Transpose[{Range[10], Range[10, 1, -1]}]; b = {{4, 7}, {9, 2}, {2, 9}, {5, 6}}; Using ReplaceAllOutside by Richard ...
• 81.2k

### Ignore higher order terms in an expression

expr = α β + α^2 + β^2 + α β^2/2 + α^2 β; vars = {α, β}; Another way is to use PolynomialDegree by Dennis M Schneider and ...
• 27.5k

### Ignore higher order terms in an expression

Assuming the parts of the expression will consist of things that look like $\alpha ^i \beta^j$ for non-negative $i , j$ We can also use Select: ...
• 4,587
Accepted

### Ignore higher order terms in an expression

Rules do not understand mathematics, they understand structures of expressions. So, without help, they don't understand that in $\alpha^2\beta$ you can read it as $\alpha^2\beta^1$, and therefore ...
• 6,246

### Ignore higher order terms in an expression

If \[Alpha], \[Beta] are small of equal order try ...
• 54.9k

### Taking the square root of the first element of a list

list = {{4, 1}, {9, 2}, {16, 3}, {25, 4}}; Using ColumnMap by Michael Sollami CMap = ResourceFunction["ColumnMap"]; ...
• 81.2k

### Taking the square root of the first element of a list

Query[All, {1 -> Sqrt}]@lst (* {{2, 1}, {3, 2}, {4, 3}, {5, 4}} *) For 'in place' modification: ...
• 20.8k

### Taking the square root of the first element of a list

lst = {{4, 1}, {9, 2}, {16, 3}, {25, 4}}; Using MapThread: ...
• 27.5k

### Taking the square root of the first element of a list

list = {{4, 1}, {9, 2}, {16, 3}, {25, 4}}; NewList = list /. {x_, y_} :> {Sqrt[x], y}
• 774

### Replace multiple elements in a list

s = {1, 5, 7, 8, 11, 10, 3}; z = {1, 3, 5}; Using MapIf by Taliesin Beynon: ...
• 27.5k

### Replace multiple elements in a list

list = {1, 5, 7, 8, 11, 10, 3}; z = {1, 3, 5}; 1. Using MapCases by Richard Hennigan (Wolfram Research) ...
• 81.2k

### Function to replace values of elements of matrix with 0 unless the value is -1

For something different (an example that can be generalized): The test matrix: mat = RandomInteger[{-4, 4}, {10, 6}]; The approach: ...
• 62.8k
1 vote

### Function to replace values of elements of matrix with 0 unless the value is -1

SeedRandom[1]; m = RandomInteger[{-3, 3}, {4, 7}]; Using SubsetMap: ...
• 27.5k

### Function to replace values of elements of matrix with 0 unless the value is -1

SeedRandom[1]; m = RandomInteger[{-3, 3}, {4, 7}]; Using MapIf by Taliesin Beynon ...
• 81.2k
1 vote

### Delete the sublist which can be others' subsets

DeleteSublists[list_] := With[{p = Permutations[list, {2}]}, DeleteCases[ list, Alternatives @@ Pick[p, Apply[SubsetQ] /@ p][[All, 2]]]] ...
• 81.2k

### MatchQ returns False for a match for e1 ** e2 while matching both e1 and e2

Using RealValuedNumberQ (new in 13.3) MatchQ[(2 e1) ** (-2 e2), (k1_?RealValuedNumberQ x_) ** (k2_?RealValuedNumberQ y_)] True ...
• 81.2k

### Replace a column/row of a matrix under a condition by a random number

m = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; Using Cases ...
• 81.2k

### Replace pattern with the number of matches so far

More alternatives that avoid an extra counter variable... inp = {x, y, z, x, y, x, x, z}; Let MapIndexed manage the state after ...
• 30.4k

### Replace last element of a list if there is somewhere a 0 in the list

If all members list numbers: ...
• 62.8k

...
• 62.8k

### Replace pattern with the number of matches so far

inp = {x, y, z, x, y, x, x, z}; Using Fold: ...
• 27.5k

### Replace last element of a list if there is somewhere a 0 in the list

Grabbing the @eldo's list: list = {{5, 6, 0, 8, 5, 9}, {8, 4, 4, 3, 5, 8}, {9, 4, 3, 2, 5, 7}, {1, 2, 3, 0, 0, 3}}; Using ...
• 27.5k

### Replace last element of a list if there is somewhere a 0 in the list

list = {{5, 6, 0, 8, 5, 9}, {8, 4, 4, 3, 5, 8}, {9, 4, 3, 2, 5, 7}, {1, 2, 3, 0, 0, 3}}; Using MapIf by Taliesin ...
• 81.2k

### Replace pattern with the number of matches so far

inp = {x, y, z, x, y, x, x, z}; Using SubsetMap (new in 12.0) ...
• 81.2k
1 vote

### Replace elements that do not match a pattern

mat = {{0, a, b}, {c, 0, d}, {0, 0, e}}; A hash-free variant of E. Chan-López answer using SameAs (new in 13.1) ...
• 81.2k
1 vote

### Replace elements that do not match a pattern

mat = {{0, a, b}, {c, 0, d}, {0, 0, e}}; Using ReplaceList: ...
• 27.5k

### Replace elements that do not match a pattern

mat = {{0, a, b}, {c, 0, d}, {0, 0, e}}; Using MapCases by Richard Hennigan (Wolfram Research) ...
• 81.2k

### How to make ReplaceAll recognize what to be replaced in a situation like this?

A short variant of my first answer rep[f_] := Expand[f] /. a_*_Symbol + _[__] :> a ...
• 81.2k
1 vote

### How to delete a pattern from String?

StringReplace and a regular expression with a negative lookahead ...
• 20.8k

### How to delete a pattern from String?

str = "{Aaaa -> a, Bbbb -> b, Cccc -> , Ddddd -> c, Eeeee -> , Fffff -> e}"; Using SequenceCases <...
• 81.2k

### Change nested list of symbols to nested list of numbers

symbols = {e4, {e200, {e1, {e11, e23}}}}; Using Replace ...
• 81.2k

### How to replace a space by a comma

str = "{1 2 3 4 5 6 7 8}"; Using StringCases with NumberString ...
• 81.2k