Why is numpy.array() is sometimes very slow?

后端 未结 2 1546
余生分开走
余生分开走 2020-12-31 06:02

I\'m using the numpy.array() function to create numpy.float64 ndarrays from lists.

I noticed that this is very slow when either the list contains None or a list of l

2条回答
  •  忘掉有多难
    2020-12-31 06:29

    I've reported this as a numpy issue. The report and patch files are here:

    https://github.com/numpy/numpy/issues/3392

    After patching:

    # was 240 ms, best alternate version was 3.29
    In [5]: %timeit numpy.array([None]*100000)
    100 loops, best of 3: 7.49 ms per loop
    
    # was 353 ms, best alternate version was 9.65
    In [6]: %timeit numpy.array([[0.0]]*100000)
    10 loops, best of 3: 23.7 ms per loop
    

提交回复
热议问题