gpt4 book ai didi

numpy - 从 numpy 列表数组创建列表的最快方法

转载 作者:行者123 更新时间:2023-12-04 10:51:52 24 4
gpt4 key购买 nike

我有一个 numpy 列表数组。这是 numpy.ndarray 类型:

   array([list([2692, 2711]), list([2751, 2770]), list([3455, 3462]),
list([4020, 4027]), list([7707, 7726]), list([7893, 7912]),
list([8118, 8126]), list([8174, 8179]), list([8215, 8234]),
list([9227, 9246]), list([9518, 9537]), list([9839, 9859]),
list([10002, 10021]), list([10024, 10043]), list([10158, 10178]),
list([11346, 11365])], dtype=object)

我想从每个子列表的第一个元素创建一个列表。我是通过列表理解来做的:
 lst = [ x[1] for x in m ]

有没有更快的方法来创建这个列表?

最佳答案

>>> m[:, 0]
array([2692, 2751, 3455, 4020, 7707, 7893, 8118, 8174, 8215, 9227, 9518,
9839, 10002, 10024, 10158, 11346], dtype=object)

关于numpy - 从 numpy 列表数组创建列表的最快方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59445668/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com