How to create a numpy array of all True or all False?

前端 未结 7 2092
醉话见心
醉话见心 2020-12-07 09:24

In Python, how do I create a numpy array of arbitrary shape filled with all True or all False?

相关标签:
7条回答
  • 2020-12-07 10:00
    >>> a = numpy.full((2,4), True, dtype=bool)
    >>> a[1][3]
    True
    >>> a
    array([[ True,  True,  True,  True],
           [ True,  True,  True,  True]], dtype=bool)
    

    numpy.full(Size, Scalar Value, Type). There is other arguments as well that can be passed, for documentation on that, check https://docs.scipy.org/doc/numpy/reference/generated/numpy.full.html

    0 讨论(0)
提交回复
热议问题