推荐学习书目
› 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 · 3231 views
    This topic created in 3002 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
    ipwx
    Aug 21, 2018
    1
    preds 的原值八成不是 list of list,是 numpy.array([[..]])。

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