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
songdg
V2EX  ›  Python

请教类似[ 0 1 2 3 4 5]如何转化成列表

  •  
  •   songdg · 2019-07-11 21:33:19 +08:00 · 1777 次点击
    这是一个创建于 1722 天前的主题,其中的信息可能已经有所发展或是发生改变。
    请教类似[ 0 1 2 3 4 5]如何转化成列表
    5 条回复    2019-07-12 14:32:13 +08:00
    songdg
        1
    songdg  
    OP
       2019-07-11 21:37:08 +08:00
    使用了 np.nonzero 生成的类似[ 0 1 2 3 4 5]如何转化成列表内置的列表
    sikariba
        2
    sikariba  
       2019-07-11 21:46:44 +08:00
    返回的是 tuple,你先 indexing 一下再掉 list 构造函数就可以了吧?有什么特殊要求吗
    Takamine
        3
    Takamine  
       2019-07-11 21:49:07 +08:00
    这个是字符串吗,字符串的话可以这样。
    s1 = "[ 0 1 2 3 4 5]"
    arr = [x for x in s1[::2][1:]]
    dongxiao
        4
    dongxiao  
       2019-07-11 21:52:28 +08:00   ❤️ 1
    @songdg #1 np.nonzero(range(1, 5))[0].tolist()
    songdg
        5
    songdg  
    OP
       2019-07-12 14:32:13 +08:00
    @dongxiao 谢谢帮助。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5333 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 08:19 · PVG 16:19 · LAX 01:19 · JFK 04:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.