That's the input I've put
dagny[x_] := x^2;
Map[dagny, {4, 9, {8, {5}}, {2, 3}}, {2}]
Output:
{4, 9, {64, {25}}, {4, 9}}
But this not I want.
I wanna {4, 9, {64, {5}}, {4, 9}}
How to Map that at a specific Level?
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityThat's the input I've put
dagny[x_] := x^2;
Map[dagny, {4, 9, {8, {5}}, {2, 3}}, {2}]
Output:
{4, 9, {64, {25}}, {4, 9}}
But this not I want.
I wanna {4, 9, {64, {5}}, {4, 9}}
How to Map that at a specific Level?
ClearAll[dagny]
dagny[x : Except[_List]] := x^2;
dagny[x_] := x
Map[dagny, {4, 9, {8, {5}}, {2, 3}}, {2}]
{4, 9, {64, {5}}, {4, 9}}
Do you mean this?
MapAt[dagny, {4, 9, {8, {5}}, {2, 3}}, {{3, 1}, {4}}]
Map[If[! ListQ[#], #^2, #] &, {4, 9, {8, {5}}, {2, 3}}, {2}]
$\endgroup$
Jan 29, 2020 at 6:19
AtomQ
.
$\endgroup$
Jan 29, 2020 at 6:28
AtomQ?
can u write it in the answer?
$\endgroup$
Map[If[AtomQ[#], #^2, #] &, {4, 9, {8, {5}}, {2, 3}}, {2}]
. Alternatively, you could modify the definition of your function to be mapped: dagny[x_?AtomQ] := x^2; dagny[x_] := x
.
$\endgroup$
Jan 29, 2020 at 6:41