all() function and any() function

Sometimes the AND function in pythonis used when operating on the array in . Here is a record:: Return when the iterable object is empty . Or when iterables whether all values are all values are then returned . Otherwise, it returns . : Return when the iterable object is empty . Or when there is a value for the iterable object , if it exists, return , otherwise return . code show as below:pythonall()any()
all()TrueTrueTrueTrueFalse
any()FalseTrueTrueFalse

import numpy as np


class Debug:
    @staticmethod
    def pythonFunction():
        x = np.array([0, 1, 2])
        print(x.all())
        print(x.any())


if __name__ == '__main__':
    debug = Debug()
    debug.pythonFunction()
"""
False
True
"""

We can see that there is a 0value in the array, which is equivalent to False, so .all()it returns Falsewhen used .any(), and returns when used True. If the array is empty, skip here, you can try it yourself.

The code word is not easy, if you find it useful, please raise your hand to give a like and let me recommend it for more people to see~

Guess you like

Origin blog.csdn.net/u011699626/article/details/112256497