V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2020-04-29 17:39:45 +08:00 · 1770 次点击
    这是一个创建于 1464 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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 条回复    2020-05-08 14:16:11 +08:00
    chizuo
        1
    chizuo  
       2020-04-29 17:49:16 +08:00
    为什么要取呢?
    直接 x = np.asarray(c)
    不就行了?
    BaseVariable
        2
    BaseVariable  
    OP
       2020-04-29 18:44:46 +08:00
    @chizuo 对啊。。是我想错了
    necomancer
        3
    necomancer  
       2020-05-08 14:16:11 +08:00
    c = np.empty((1000,1000,3))
    c[...,:]=a
    c = np.transpose(c, (2,0,1))
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   829 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 22:44 · PVG 06:44 · LAX 15:44 · JFK 18:44
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.