Considering I have a list:
F = {f1, f2, f3, f4}
I want to perform exponent on the list
F = Power[#, 2]& /@ F
Now I want to do the same but with conditions. I want to perform Power[#, 2]
on the elements of F
that are not equal to NULL
and the result of Power[#, 2]
is not null.
Thanks.
UPDATE:
Let's say I have
`A = {x, y, z}`
SomeAction[t_] := ...
SomeAction[#] &/@ A
Let's say x = NULL
As Harry commented SomeAction[#] &/@ Select[A, !(# === NULL) &]
will work only on y
and z
.
Let's also say that SomeAction[y] = NULL
, and in this case I want to take the original y
.
So I want to have following
A
= ...SomeAction[#] &/@ Select[A, !(# === NULL) &]
... be equivalent to
A = {y, SomeAction[z]}
list = {1, 2, 3, Null, 4}; MapAt[#^2 &, list, Position[list, x_ /; ! (x === Null), {1}, Heads -> False]]
? $\endgroup$ – Harry Feb 16 '15 at 11:08list = {1, 2, 3, Null, 4}; #^2 & /@ Select[list, ! (# === Null) &]
? $\endgroup$ – Harry Feb 16 '15 at 11:11Listable
attribute it usually much faster than usingMap
in this way, so you could tryF^2 /. Null^2 -> Null
. $\endgroup$ – C. E. Feb 16 '15 at 11:12