推荐学习书目
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
z0z
V2EX  ›  Python

在 Python 中,矩阵或向量可以在中括号中判断的吗?

  •  
  •   z0z · Aug 21, 2018 · 2950 views
    This topic created in 2855 days ago, the information mentioned may be changed or developed.

    preds 的原值是

    preds= [[0.46720526]

    [0.99414194]

    [0.26025357]

    [0.99096197]

    [0.99137177]]

    经过下面的操作之后

    preds[preds <= 0.5] = 0
    
    preds[preds > 0] = 1
    

    就把小于 0.5 的设置为 0,大于 0 的设置为 1 了

    [[0.]

    [1.]

    [0.]

    [1.]

    [1.]]

    请问这样的神操作学名叫什么呢?是什么原理呢?

    5 replies    2018-08-21 10:34:27 +08:00
    ipwx
        1
    ipwx  
       Aug 21, 2018
    preds 的原值八成不是 list of list,是 numpy.array([[..]])。

    numpy.array 重写了 __getitem__。
    ipwx
        2
    ipwx  
       Aug 21, 2018
    重写了 __getitem__ 和 __setitem__
    princelai
        3
    princelai  
       Aug 21, 2018
    justou
        4
    justou  
       Aug 21, 2018
    numpy 里面叫 fancy indexing, 翻译成花式索引
    z0z
        5
    z0z  
    OP
       Aug 21, 2018
    @ipwx
    @princelai
    @justou 仰慕三位大神,表示感谢,我去学习学习
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5299 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 03:51 · PVG 11:51 · LAX 20:51 · JFK 23:51
    ♥ Do have faith in what you're doing.