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
NBurton
V2EX  ›  Python

numpy 和 pandas,如何通过一个数组的值确定另一个数组的值

  •  
  •   NBurton · 2017-04-13 11:07:58 +08:00 · 2430 次点击
    这是一个创建于 2583 天前的主题,其中的信息可能已经有所发展或是发生改变。
    例如, array1 是一组数字,有正有负, array2 根据 array1 的值,如果是正,就是 True ,否则就是 False 。
    应该有一种非常简便的方式实现,不需要 for 循环,请大家赐教,谢谢。
    4 条回复    2017-04-13 22:05:32 +08:00
    billgreen1
        1
    billgreen1  
       2017-04-13 11:09:35 +08:00
    array2 = map(lambda x: x>0, array1)
    Zzzzzzzzz
        2
    Zzzzzzzzz  
       2017-04-13 11:16:41 +08:00
    numpy_array2 = numpy_array1>0
    imn1
        3
    imn1  
       2017-04-13 11:19:21 +08:00
    EmdeBoas
        4
    EmdeBoas  
       2017-04-13 22:05:32 +08:00   ❤️ 2
    =-=.... so easy

    In [1]: a = np.array([1,-1,1,-1])

    In [2]: b = (a > 0)

    In [3]: b
    Out[3]: array([ True, False, True, False], dtype=bool)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5499 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 09:33 · PVG 17:33 · LAX 02:33 · JFK 05:33
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.