5
$\begingroup$

I have two matrix

  x={{2, 3, 4}, {3, 4, 5}, {4, 5, 6}};
  probability={{0.09, 0.09, 0.12}, {0.09, 0.09, 0.12}, {0.12, 0.12, 0.16}};

Now I want to add up corresponding position probability. for example,

$\Pr(x=3)=0.09+0.09$

$\Pr(x=4)=0.12+0.09+0.12$

I tried Position

   k = Position[x, 3];
  (*   {{1, 2}, {2, 1}}  *)

but they can not directly use

 x[[k]]

Which command should I use?

$\endgroup$

3 Answers 3

6
$\begingroup$
 Total@Extract[probability, Position[x, 3]]
$\endgroup$
4
$\begingroup$
Total[Pick[probability, x, 3], 2]
$\endgroup$
0
$\begingroup$
emp = EmpiricalDistribution[Flatten @ probability -> Flatten @ x]
p[n_] := Probability[z == n, z \[Distributed] emp]

E.g.

p[3]

0.18

p[4]

0.33

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.