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
110male
V2EX  ›  Python

[numpy]这个什么意思

  •  
  •   110male · 2017-12-25 15:13:33 +08:00 · 1968 次点击
    这是一个创建于 2285 天前的主题,其中的信息可能已经有所发展或是发生改变。

    import numpy as np

    a = np.array([[1,2], [3, 4], [5, 6]])

    An example of integer array indexing.

    The returned array will have shape (3,) and

    print a[[0, 1, 2], [0, 1, 0]] # Prints "[1 4 5]" 这什么意思,我怎么不懂 给解释一下

    110male
        1
    110male  
    OP
       2017-12-25 15:14:59 +08:00
    a = np.array([[1,2], [3, 4], [5, 6]])
    print a[[0, 1, 2], [0, 1, 0]]

    结果是: "[1 4 5]"
    什么意思?
    z0z
        2
    z0z  
       2017-12-25 15:29:55 +08:00   ❤️ 1
    import numpy as np
    a = np.array([[1,2],[3,4],[5,6]])
    print(a[[0,1,2]])
    print("=========")
    print(a[[0,1,0]])
    print("=========")
    print(a[[0,1,2],[0,1,0]])





    [[1 2]
    [3 4]
    [5 6]]
    =========
    [[1 2]
    [3 4]
    [1 2]]
    =========
    [1 4 5]

    Process finished with exit code 0
    ProkillerJ
        3
    ProkillerJ  
       2017-12-25 20:03:57 +08:00   ❤️ 1
    a[[x1, x2, x3], [y1, y2, y3]] 相当于[a[x1,y1],a[x2,y2],a[x3,y3]]
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3330 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 13:43 · PVG 21:43 · LAX 06:43 · JFK 09:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.