推荐学习书目
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

不知道数组有没有占位符这样一个概念

  •  
  •   songdg · Oct 7, 2018 · 4112 views
    This topic created in 2785 days ago, the information mentioned may be changed or developed.
    arr = np.array([None,3,4])用 None 占一个位没问题,但用 np.max(arr)却不能求最大值,提示 TypeError: '>=' not supported between instances of 'NoneType' and 'int'。我想知道有没有一个占位符但不参与运算。
    7 replies    2018-10-10 19:00:08 +08:00
    sww4718168
        1
    sww4718168  
       Oct 7, 2018   ❤️ 1
    np.nan ?
    nroskill
        2
    nroskill  
       Oct 7, 2018
    求最大的话还是加个 INT_MIN 吧
    不知道你的具体需求是啥,感觉像走了歪路
    ghhardy
        3
    ghhardy  
       Oct 7, 2018 via Android
    @nroskill 哈哈,也许是应该用 mask 实现的东西
    enzo113
        4
    enzo113  
       Oct 7, 2018
    可以试试 -float("inf")
    PythonAnswer
        5
    PythonAnswer  
       Oct 7, 2018 via iPhone
    一般要干掉 nan 才好计算,这是数据清理的基本要求,框架不会自动帮你省略。
    Belmode
        6
    Belmode  
       Oct 8, 2018 via Android
    为什要占位呢?直接过滤出数据,再处理不久行了
    songdg
        7
    songdg  
    OP
       Oct 10, 2018
    numpy.nanmin、numpy.nanmax 解决了这个问题。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2742 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 170ms · UTC 02:20 · PVG 10:20 · LAX 19:20 · JFK 22:20
    ♥ Do have faith in what you're doing.