Machine Learning Prerequisites (Numpy)

You are currently auditing this course.
27 / 32

Numpy - Mathematical Operations on NumPy Arrays - Conditional Operators

Conditional operators (like <, >, etc.) are also applied element-wise.

e.g.

import numpy as np
m = np.array( [ 20, -5, 30, 40] )

m < [15, 16, 35, 36]

Output will be

array([ False, True, True, False], dtype=bool)

Now let us check for another condition

m< 25

Output will be

array( [ True, True, False, False], dtype=bool )

To get the elements below a value of 25, you can use the below syntax

m[m<25]

Output will be

 array( [20, -5 ] )
INSTRUCTIONS

Please follow the below steps:

(1) Please import the required libraries

import numpy as np

(2) Please create a NumPy array called U, as shown below

U = np.array([ [ 22, 45], [90, 4 ] ] )

(3) Get all the elements of U which are less than 45, and print the result using the print() function

print( << your code comes here>> )
See Answer

No hints are availble for this assesment

Loading comments...