如何从多维数组访问数据

时间:2014-07-29 08:46:17

标签: python arrays multidimensional-array

我在python中有一个类似于:

的数组

编辑:对不起,数据如下所示:

1. [array([[[23,  2]]]), array([[[21,  2]],

               [[21,  3]],

               [[21,  4]],

               [[22,  4]],

               [[23,  4]],

               [[22,  4]],

               [[21,  3]]])]
2. [array([[[28, 26]],

       [[28, 27]],

       [[28, 28]],

       [[28, 29]],

       [[28, 30]],

       [[29, 30]],

       [[30, 30]],

       [[31, 30]],

       [[31, 29]],

       [[31, 28]],

       [[31, 27]],

       [[30, 26]],

       [[29, 26]]])]
    And after using print array_name[0] it looks like this:
        1. [[[23  2]]]
        2. [[[28 26]]

         [[28 27]]

         [[28 28]]

         [[28 29]]

         [[28 30]]

         [[29 30]]

         [[30 30]]

         [[31 30]]

         [[31 29]]

         [[31 28]]

         [[31 27]]

         [[30 26]]

         [[29 26]]]

现在我只想阅读第一部分,即[23 2]和[28 26]。它是如何做到的?

列表分为多个数组。

1 个答案:

答案 0 :(得分:1)

import numpy
l1 = [numpy.array([[[23, 2]]]), numpy.array([[[21, 2]], [[21, 3]], [[21, 4]], [[22, 4]], [[23, 4]],
     [[22, 4]], [[21, 3]]])]

l2 = [numpy.array([[[28, 26]], [[28, 27]],[[28, 28]], [[28, 29]], [[28, 30]], [[29, 30]], [[30, 30]], [[31, 30]],
     [[31, 29]], [[31, 28]],[[31, 27]], [[30, 26]],[[29, 26]]])]

print l1[0]     # -> [[[23  2]]]
print l2[0][0]  # -> [[28 26]]