矩阵中的Python矩阵

时间:2012-10-09 10:12:58

标签: python

在我的程序中,我使用这个var:

payoff_matrix = [ [(4,4),(1,6)] , [(6,1),(2,2)] ]

我需要检查(4,4)和(2,2),(它可以是任何东西) 我用

  a=payoff_matrix[0]
  b=a[0]
  c=b[0]
  d=b[1]

结果是

  c=4
  d=4

我可以像

那样去做
c=payoff_matrix[0].[0].[0]

还是以某种方式?

1 个答案:

答案 0 :(得分:1)

In [4]: mat = [ [(4,4),(1,6)] , [(6,1),(2,2)] ]

In [6]: c,d=mat[0][0]    #here mat[0] is [(4,4),(1,6)], invoking [0] on this yields [4,4]

In [7]: c
Out[7]: 4

In [8]: d
Out[8]: 4


In [9]: a,b=mat[1][1]  #here mat[1] is [(6,1),(2,2)], invoking [1] on this yields [2,2]

In [10]: a
Out[10]: 2

In [11]: b
Out[11]: 2