如何从多维数组访问数据

时间:2021-08-22 21:34:05

I have an array in python which looks like:

我在python中有一个数组,看起来像:

Edit: Sorry, the data looks like follows:

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

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]]]

Now I would like to read only the first part, i.e. [23 2] and [28 26]. How do it do that?

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

The list is divided into multiple arrays.

该列表分为多个数组。

1 个解决方案

#1


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]]

#1


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]]