[英]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,...)
我是 python 的新手,我在这里有这个数组,我想像第一列一样访问每个数组的一列(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:但我试过myexamplearray[:][0]
并且这个命令只返回数据:
array([[ 0.04598266, -0.21463124, 0.00395878, 0.27825043]],
dtype=float32)
When i try myexamplearray[:,0]
i get:当我尝试myexamplearray[:,0]
时,我得到:
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)原因是您的数组秘密是 3D 数组而不是 2D (每行有 2 [ 而不是 1 )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.