2013-10-26 196 views
0

我有陣列的列表如下所示:從數組列表中獲取每個數組的元素?

[array([ 3.04347826, 3.04347826, 3.04347826, 3.04347826, 3.04347826, 
    3.04347826, 3.04347826, 3.04347826, 3.04347826, 3.04347826, 
    3.04347826, 3.04347826, 3.04347826, 3.04347826, 3.04347826, 
    3.04347826, 3.04347826, 3.04347826, 3.04347826, 3.04347826, 
    3.04347826, 3.04347826, 3.04347826]), array([ 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 
    3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 
    3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 
    3.5, 3.5, 3.5, 3.5, 3.5]), array([ 3.08823529, 3.08823529, 3.08823529, 3.08823529, 3.08823529, 
    3.08823529, 3.08823529, 3.08823529, 3.08823529, 3.08823529, 
    3.08823529, 3.08823529, 3.08823529, 3.08823529, 3.08823529, 
    3.08823529, 3.08823529, 3.08823529, 3.08823529, 3.08823529, 
    3.08823529, 3.08823529, 3.08823529, 3.08823529, 3.08823529, 
    3.08823529, 3.08823529, 3.08823529, 3.08823529, 3.08823529, 
    3.08823529, 3.08823529, 3.08823529, 3.08823529]), array([ 3.84848485, 3.84848485, 3.84848485, 3.84848485, 3.84848485, 
    3.84848485, 3.84848485, 3.84848485, 3.84848485, 3.84848485, 
    3.84848485, 3.84848485, 3.84848485, 3.84848485, 3.84848485, 
    3.84848485, 3.84848485, 3.84848485, 3.84848485, 3.84848485, 
    3.84848485, 3.84848485, 3.84848485, 3.8484848.... 

我怎麼只有每個數組的第一個元素?

回答

4

這可以工作,假設陣列是numpy.array

first_elements = [e[0] for e in list1] 

其中:

list1是您的陣列的列表

first_elements是在list1

與每個陣列的第一個元素的列表

以更清晰的方式:

first_elements = [] 
for arr in list1: 
    first_elements.append(arr[0]) 
相關問題