推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
BaseVariable
V2EX  ›  Python

遍历 list of lists of lists 的优化方法

  •  
  •   BaseVariable · Apr 29, 2020 · 2943 views
    This topic created in 2346 days ago, the information mentioned may be changed or developed.

    a = [1, 2, 3] b = [a for i in range(1000)] c = [b for i in range(1000)] 现在想从 c 取每个 int (每个 1 、2 、3 ),然后构成一个 3x1000x1000 的 numpy matrix 求问大佬们有什么除了遍历以外更快的方法。 感激不尽!

    3 replies  •  2020-05-08 14:16:11 +08:00
    chizuo
        1
    chizuo  
       Apr 29, 2020
    为什么要取呢?
    直接 x = np.asarray(c)
    不就行了?
    BaseVariable
        2
    BaseVariable  
    OP
       Apr 29, 2020
    @chizuo 对啊。。是我想错了
    necomancer
        3
    necomancer  
       May 8, 2020
    c = np.empty((1000,1000,3))
    c[...,:]=a
    c = np.transpose(c, (2,0,1))
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2357 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 02:01 · PVG 10:01 · LAX 19:01 · JFK 22:01
    ♥ Do have faith in what you're doing.