Comparison of all elements of two tuples (with all functions ())

So, I know that tuple comparisons work lexicographically:

Tuples and lists are compared lexicographically, using a comparison of the corresponding elements. This means that to compare equality, each element must be compared with equal, and two sequences must be of the same type and have the same length.

     

If not the same, the sequences are ordered in the same way as their first different elements. For example, cmp ([1,2, x], [1,2, y]) returns the same as cmp (x, y). If the corresponding element does not exist, the shorter sequence is ordered first (for example, [1,2] <[1,2,3]).

So from this:

>>> a = (100, 0)
>>> b = (50, 50)
>>> a > b
True

2 , - ( ):

>>> a > b
(True, False) #returned tuple containing each comparison
>>> all(a > b)
False

- , , - "" (0,0), , , ord > (0,0), x 0, y , , , .

/:
, . - , , ( ), , - , . ?

+3
5

zip-:

>>> a = (100, 0)
>>> b = (50, 50)
>>> [(a > b) for a, b in zip(a,b)]
[True, False]

() any() .

+7

a > b tuple(i > j for i, j in zip(a,b)) .

>>> a = (100, 0)
>>> b = (50, 50)
>>> tuple(i > j for i, j in zip(a,b))
(True, False)
>>> all(i > j for i, j in zip(a,b))
False
+1

, / :

>>> import numpy
>>>
>>> a = (100, 0)
>>> b = (50, 50)
>>> numpy.array(a) > b
array([ True, False], dtype=bool)
>>> 
>>> (numpy.array(a) > b).any()
True
>>> (numpy.array(a) > b).all()
False
  • numpy , any()/all(), . ( ), 'a' 'b' numpy . , : , Python numpy. , : (1) ( ); (2) ; (3) .

  • , numpy 'b', , . , numpy, , , / , ( numpy-to-numpy). .:)

+1

, :

[ai > bi for ai,bi in zip(a,b)]

, , , - :

if a >= (0.,0.):
    print "a has only positive values"
else:
    print "a has at least one negative value"

Python , , .

if (False,False):
    print "True!" # This is what is printed.
else:
    print "False!"

, .

0
source

It seemed to me that the use of maps and lambda functions is missing in the answers

>>> a = (100, 0)
>>> b = (50, 50)
>>> all(map(lambda x,y: x > y, a, b)
False
0
source

All Articles