python调用数组元素_从python中的嵌套数组访问元素

发布于:2021-09-13 13:49:35

假设我有以下数组


test=np.asarray([


[[ 0.26139668, 0.271985 , 0.89647514, 0.10352486],


[ 0.30488212, 0.31384717, 0.84089744, 0.15910256],


[ 0.32112577, 0.32958562, 0.79216727, 0.20783273]],


[[ 0.6017121 , 0.60530397, 0.49432092, 0.50567908],


[ 0.61610247, 0.61954059, 0.49649699, 0.50350301],


[ 0.63149809, 0.63477652, 0.49945702, 0.50054298]],


[[ 0.6017121 , 0.60530397, 0.49432092, 0.50567908],


[ 0.61610247, 0.61954059, 0.49649699, 0.50350301],


[ 0.63149809, 0.63477652, 0.49945702, 0.50054298]],


[[ 0.6017121 , 0.60530397, 0.49432092, 0.50567908],


[ 0.61610247, 0.61954059, 0.49649699, 0.50350301],


[ 0.63149809, 0.63477652, 0.49945702, 0.50054298]]])


现在,我要查找的结果在测试中每个元素的第一列中.所以基本上我需要test [0] [:, 0]和test [1] [:, 0] …,最后是test [3] [:, 0].


我敢肯定,没有for循环就可以做到吗?


因为符号[:]应该表示从头到尾的所有元素,所以我什至尝试过test [:] [:, 0].那没用. test [:,0] [:, 0]也不好.


那么,什么是替代for循环的呢?


结果应为:


[0.26139668, 0.30488212, 0.32112577, 0.6017121, 0.61610247, 0.63149809,


0.6017121, 0.61610247, 0.63149809,0.6017121, 0.61610247, 0.63149809]


或类似的东西. (我只需要整个数组中的那些数字).

相关推荐