简体   繁体   中英

How to acces an 1D array of arrays in python

i'm new to python and i have this array here and i want to acces one column of each array like the first column (0.04598266, 0.04169003, 0.04129871,...)

array([[[ 0.04598266, -0.21463124,  0.00395878,  0.27825043]],

       [[ 0.04169003, -0.01956599,  0.00952379, -0.01318127]],

       [[ 0.04129871,  0.1754181 ,  0.00926016, -0.30284417]],

       ...,

       [[ 0.19837196,  0.24495168,  0.00459207, -0.27469254]],

       [[ 0.20327099,  0.04976451, -0.00090178,  0.0194352 ]],

       [[ 0.20426628, -0.1453445 , -0.00051308,  0.31183347]]],
      dtype=float32)

but i've tried myexamplearray[:][0] and this command returns only the data:

array([[ 0.04598266, -0.21463124,  0.00395878,  0.27825043]],
      dtype=float32) 

When i try myexamplearray[:,0] i get:

array([[ 0.04598266, -0.21463124,  0.00395878,  0.27825043],
       [ 0.04169003, -0.01956599,  0.00952379, -0.01318127],
       [ 0.04129871,  0.1754181 ,  0.00926016, -0.30284417],
       ...,
       [ 0.19837196,  0.24495168,  0.00459207, -0.27469254],
       [ 0.20327099,  0.04976451, -0.00090178,  0.0194352 ],
       [ 0.20426628, -0.1453445 , -0.00051308,  0.31183347]],
      dtype=float32)

Anyone can help me?

You should try:

print(myexamplearray[:,0,0])

Which prints:

[0.04598266 0.04169003 0.04129871 0.19837196 0.20327099 0.20426628]

The reason is that your array is secretly a 3D array instead of a 2D (every row has 2 [ instead of 1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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