我有一个数组列表,如下所示:
[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....
如何只获取每个数组的第一个元素?
答案 0 :(得分: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])