fork download
  1. import numpy as np
  2.  
  3. N = 53 # カードの総数(ジョーカー1枚追加)
  4.  
  5. pxy = np.zeros((2, 2)) # 同時確率
  6. for x in range(2): # x=0: ダイヤではない, x=1: ダイヤである
  7. for y in range(2): # y=0: 絵札ではない, y=1: 絵札である
  8. if x == 0 and y == 0:
  9. n = N - (12 + 13 - 3) # 30枚(ジョーカー含む)
  10. elif x == 0 and y == 1:
  11. n = 9
  12. elif x == 1 and y == 0:
  13. n = 10
  14. elif x == 1 and y == 1:
  15. n = 3
  16. pxy[x, y] = n / N
  17.  
  18. px = np.zeros(2) # Xの周辺確率
  19. for x in range(2):
  20. px[x] = np.sum(pxy[x, :])
  21.  
  22. py = np.zeros(2) # Yの周辺確率
  23. for y in range(2):
  24. py[y] = np.sum(pxy[:, y])
  25.  
  26. for x in range(2):
  27. for y in range(2):
  28. print(
  29. "(x,y)=",
  30. x,
  31. y,
  32. "( 同時確率=%5.4f" % pxy[x, y],
  33. " 周辺確率の積=%5.4f" % (px[x] * py[y]),
  34. )
Success #stdin #stdout 0.08s 23520KB
stdin
Standard input is empty
stdout
('(x,y)=', 0, 0, '( \xe5\x90\x8c\xe6\x99\x82\xe7\xa2\xba\xe7\x8e\x87=0.0000', ' \xe5\x91\xa8\xe8\xbe\xba\xe7\xa2\xba\xe7\x8e\x87\xe3\x81\xae\xe7\xa9\x8d=0.0000')
('(x,y)=', 0, 1, '( \xe5\x90\x8c\xe6\x99\x82\xe7\xa2\xba\xe7\x8e\x87=0.0000', ' \xe5\x91\xa8\xe8\xbe\xba\xe7\xa2\xba\xe7\x8e\x87\xe3\x81\xae\xe7\xa9\x8d=0.0000')
('(x,y)=', 1, 0, '( \xe5\x90\x8c\xe6\x99\x82\xe7\xa2\xba\xe7\x8e\x87=0.0000', ' \xe5\x91\xa8\xe8\xbe\xba\xe7\xa2\xba\xe7\x8e\x87\xe3\x81\xae\xe7\xa9\x8d=0.0000')
('(x,y)=', 1, 1, '( \xe5\x90\x8c\xe6\x99\x82\xe7\xa2\xba\xe7\x8e\x87=0.0000', ' \xe5\x91\xa8\xe8\xbe\xba\xe7\xa2\xba\xe7\x8e\x87\xe3\x81\xae\xe7\xa9\x8d=0.0000')