推荐学习书目
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 · Apr 13, 2017 · 2992 views
    This topic created in 3316 days ago, the information mentioned may be changed or developed.
    例如, array1 是一组数字,有正有负, array2 根据 array1 的值,如果是正,就是 True ,否则就是 False 。
    应该有一种非常简便的方式实现,不需要 for 循环,请大家赐教,谢谢。
    4 replies    2017-04-13 22:05:32 +08:00
    billgreen1
        1
    billgreen1  
       Apr 13, 2017
    array2 = map(lambda x: x>0, array1)
    Zzzzzzzzz
        2
    Zzzzzzzzz  
       Apr 13, 2017
    numpy_array2 = numpy_array1>0
    imn1
        3
    imn1  
       Apr 13, 2017
    EmdeBoas
        4
    EmdeBoas  
       Apr 13, 2017   ❤️ 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)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5684 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 65ms · UTC 07:01 · PVG 15:01 · LAX 00:01 · JFK 03:01
    ♥ Do have faith in what you're doing.