Based on earlier question How to replace the value that include infinity?,
Now, If I have the input A
A= {-3, 0, 1,2}
and do the operation :
B = -Total[(#*Log2[#]& /@ A]
Hence, I do
If[# == 0, 0, # Log2[#]] & /@ A
hold = Hold[# Log2[#]] & /@ A
ReleaseHold[hold /. HoldPattern[0 Log2[0]] -> 0]
to replace 0.
Now, how can I not enter a negative number in the calculation in B. In other words, B only calculates the positive number and [0 Log2[0]] -> 0.
Thank you very much.