简体   繁体   English

获取 3d numpy 数组中的每一列

[英]Getting each column in a 3d numpy array

I converted an image from RBG to CieLab, now I need to use the value of the cielab to calculate some equations.我将图像从 RBG 转换为 CieLab,现在我需要使用 cielab 的值来计算一些方程。 I have been trying to get the value of each column in the array.我一直在尝试获取数组中每一列的值。 For example if I have:例如,如果我有:

List =列表 =

   [[[ 65 234 169]
     [203 191 245]
     [ 36  58 196]
     [207 208 143]
     [251 208 187]]

    [[ 79  69 237]
     [ 13 124  42]
     [104 165  82]
     [170 178 178]
     [ 66  42 210]]

   [[ 40 163 219]
    [142  37 140]
    [ 75 205 143]
    [246  30 221]
    [ 16  98 102]]]

How can I get it to give me the values of each columns like:我怎样才能得到它给我每列的值,例如:

1st_column =第一列 =

         65
         203
         36
         207
         251

         79
         13
         104
         170
         66
         
         40
         142
         75
         246
         16

Thank you.谢谢你。

Try:尝试:

>>> m[:, :, 0]
array([[ 65, 203,  36, 207, 251],
       [ 79,  13, 104, 170,  66],
       [ 40, 142,  75, 246,  16]])

As suggested by @mozway, you can use the ellipsis syntax: m[..., 0] .正如@mozway 所建议的,您可以使用省略号语法: m[..., 0]

To know more, read How do you use the ellipsis slicing syntax in Python?要了解更多信息,请阅读如何在 Python 中使用省略号切片语法?

You can also flatten your array:您还可以flatten您的阵列:

>>> m[:, :, 0].flatten()
array([ 65, 203,  36, 207, 251,  79,  13, 104, 170,  66,  40, 142,  75, 246,  16])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM