Exercise: Using Conditions on Arrays

In this exercise, you will be using multiple conditions on arrays.

We'll cover the following

Task

In this exercise, you will be using conditions on NumPy arrays.

Problem statement

  1. Create an array for variable x consisting of 2020 values from 00 to 2π2\pi.
  2. Compute sin(x)sin(x) and store it in a variable y.
  3. Store all values of y that are greater than 0.70.7 or less than 0.5-0.5 in one array.

y>0.7, y<0.5y>0.7, \space y<-0.5

  1. Store all values of y that are greater than 0.5-0.5 and less than 0.70.7 in another array.

0.5<y<0.7-0.5<y<0.7

π\pi can be accessed using np.pi.

sin(x)sin(x) can be used as np.sin(x).

Get hands-on with 1200+ tech skills courses.