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

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

  •  
  •   songdg · 2018-10-07 10:57:45 +08:00 · 3013 次点击
    这是一个创建于 2018 天前的主题,其中的信息可能已经有所发展或是发生改变。
    arr = np.array([None,3,4])用 None 占一个位没问题,但用 np.max(arr)却不能求最大值,提示 TypeError: '>=' not supported between instances of 'NoneType' and 'int'。我想知道有没有一个占位符但不参与运算。
    7 条回复    2018-10-10 19:00:08 +08:00
    sww4718168
        1
    sww4718168  
       2018-10-07 10:59:11 +08:00   ❤️ 1
    np.nan ?
    nroskill
        2
    nroskill  
       2018-10-07 13:50:23 +08:00
    求最大的话还是加个 INT_MIN 吧
    不知道你的具体需求是啥,感觉像走了歪路
    ghhardy
        3
    ghhardy  
       2018-10-07 13:58:31 +08:00 via Android
    @nroskill 哈哈,也许是应该用 mask 实现的东西
    enzo113
        4
    enzo113  
       2018-10-07 18:31:54 +08:00
    可以试试 -float("inf")
    PythonAnswer
        5
    PythonAnswer  
       2018-10-07 21:45:13 +08:00 via iPhone
    一般要干掉 nan 才好计算,这是数据清理的基本要求,框架不会自动帮你省略。
    Belmode
        6
    Belmode  
       2018-10-08 08:12:12 +08:00 via Android
    为什要占位呢?直接过滤出数据,再处理不久行了
    songdg
        7
    songdg  
    OP
       2018-10-10 19:00:08 +08:00
    numpy.nanmin、numpy.nanmax 解决了这个问题。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5480 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 06:55 · PVG 14:55 · LAX 23:55 · JFK 02:55
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.