October 2019
Beginner to intermediate
674 pages
16h 43m
English
The logical operators help compare arrays, check the type and contents of an array, and perform logical comparison between arrays.
The all and any functions help to evaluate whether all or any values along the specified axis evaluate to True. Based on the evaluation result, it returns True or False:
In [39]: array_logical = np.random.randn(3, 4)In [40]: array_logicalOut[40]:array([[ 0.79560751, 1.11526762, 1.21139114, -0.36566102],[ 0.561285 , -1.27640005, 0.28338879, 0.13984101],[-0.304546 , 1.58540957, 0.1415475 , 1.53267898]])# Check if any value is negative along each dimension in axis 0In [42]: np.any(array_logical < 0, axis = 0)Out[42]: array([ True, True, False, True])# Check if all the values are negative in the ...
Read now
Unlock full access