fork download
  1. # your code goes here
  2. import numpy as np
  3.  
  4. N = 53 # カードの総数(ジョーカー1枚追加)
  5.  
  6. pxy = np.zeros((2, 2)) # 同時確率
  7. for x in range(2): # x=0: ダイヤではない, x=1: ダイヤである
  8. for y in range(2): # y=0: 絵札ではない, y=1: 絵札である
  9. if x == 0 and y == 0:
  10. n = N - (12 + 13 - 3) # 30枚(ジョーカー含む)
  11. elif x == 0 and y == 1:
  12. n = 9
  13. elif x == 1 and y == 0:
  14. n = 10
  15. elif x == 1 and y == 1:
  16. n = 3
  17. pxy[x, y] = n / N
  18.  
  19. px = np.zeros(2) # Xの周辺確率
  20. for x in range(2):
  21. px[x] = np.sum(pxy[x, :])
  22.  
  23. py = np.zeros(2) # Yの周辺確率
  24. for y in range(2):
  25. py[y] = np.sum(pxy[:, y])
  26.  
  27. for x in range(2):
  28. for y in range(2):
  29. print(
  30. "(x,y)=",
  31. x,
  32. y,
  33. "( 同時確率=%5.4f" % pxy[x, y],
  34. " 周辺確率の積=%5.4f" % (px[x] * py[y]),
  35. )
Success #stdin #stdout 0.09s 23420KB
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')