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

前端 未结 7 2114
醉话见心
醉话见心 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

提交回复
热议问题