top of page
Search

# NumPy Part 3

## Representing missing and infinite values

• Missing values can be represented using np.nan

• Infinite values can be represented using np.inf

Example 1

np.nan Example 2

np.inf ## Checking whether an array contains and nan value or an infinite value

• To check if nan value is present in the array we will use isnan() function

• isnan() function returns True if an array contains nan or it will return False

• To check if an infinite value is present in an array we will use isinf() function

• isinf() function returns True if an array contains infinite or it will return False

Example 3

isnan() Example 4

isinf() ## Comparison operators on arrays

• We can compare the arrays by using comparison operators like (==,<,>,>=,<=)

• Comparison operators compare the arrays element wise

### == ( equal )

• To compare whether the elements are equal in the arrays

Example 5 ### != ( not equal )

• To compare whether the elements are not equal in the arrays

Example 6 ### > ( greater than )

• To compare whether the elements are greater than in the arrays

Example 7 ### < ( lesser than )

• To compare whether the elements are lesser than in the arrays

Example 8 ### >= ( greater than or equal to)

• To compare whether the elements are greater than or equal to in the arrays

Example 9 ### <= ( lesser than or equal to)

• To compare whether the elements are lesser than or equal to in the arrays

Example 10 ### array-wise comparisons

• In array - wise comparisons we compare whether the arrays are same or not

• For array-wise comparisons we will use array_equal(array1,array2) function

Example 11 ## Logical Operations

• We can also apply logical operation on arrays

• logical_or(array1,array2) and logical_and(array1,array2) functions are used to perform logical operations on arrays

### logical_or(array1,array2)

• It will compare two arrays elementwise and returns true if any one of the element is not a 0 and returns false if both the elements are 0

Example 12 ### logical_and(array1,array2)

• It will compare two arrays elementwise and returns true if both the element is not a 0 and returns false if both the elements are 0

Example 13 ## Extras:-

### np.all(array)

• np.all() function returns True if all the elements in an arrays is not 0's and returns False if any element in an array is 0's ### np.any(array)

• np.any() function returns True if any elements in an arrays is not 0's and returns False if all the elements in an array is 0's 