NumPy: Basics

  1. Indexing and Slicing

    Question 1 of 4

      Store sensor data of 24 hr temperature in a List as tmp_data = [1.3, 1.4, .., 0.8].
      1. Create a NumPy array from this list. Display array, it's shape, items data type.
      2. Display the temperature of 12 PM.
      3. Replace the temperature of 2 PM with value -1.
      4. Display temperature from 10 AM to 6 PM.
      5. Delete the temperature of 2 PM.
      6. Insert the value for 2 PM with median temperature of the day.
      7. Display minimum temperature of day and time it occurred.
      8. Display maximum temperature of day and time it occurred.
      9. Calculate the standard deviation of the temperatures.
  2. Modifying Arrays

    Question 2 of 4

      Assign info as [["Rabindra", "Instructor], ["Ram", "Student], ["Shyam", "Student"]].
      1. Create a NumPy array from this list. Display array, it's shape, items data type.
      2. Add a new row at end for Sita with role Student.
      3. Add a new column at end for Age with values 30, 25, 28, 22.
      4. Delete the row for Ram.
      5. Delete the column for Age.
      6. Add a 2 column as City with values Kathmandu, Mumbai, Newyork.
      7. Display the name of all students.
      8. Display the role of Rabindra.
      9. Display all info for Shyam.
  3. Vectorized Operation, Broadcast

    Question 3 of 4

      Store cost price of products as cost_prices = [100, 150, 200, 250, 300].
      1. Create a NumPy array from it as cp_ar. Display array, it's shape, items data type.
      2. Assuming a 13% profit, calculate the selling price for each product. Assign it as sp_ar.
      3. Calculate the profit for each product using sp_ar and cp_ar. Assign it as profit_ar.
      4. Create function price_range that accepts price & categorizes it as low, medium or high depending if its value is below 150, between 150-250 or above 250.
      5. Find price category for each product using price_range as store it as price_cat_ar.
      6. Convert values of price_cat_ar into uppercase, lowercase, titlecase & Display result.
      7. Create rev_ar by subtracting 2 from profit_ar.
      8. Round each element of sp_ar upto 2 decimal and store it as sp_ar_rounded.
  4. Vectorized Operation, Broadcast

    Question 4 of 4

    • Store stock price as [100, 150, 200, 250, 300, 270]. Using it calculate return for each day & store as returns_ar. (return = (current_price - previous_price)/previous_price)
    • A man deposits each day on bank as [10, 15, 20, 25, 30, 27]. Generate a array total_amount_ar that shows total amount deposited over the time. [10, 25, 45, ...].
    • You have a co2 emission data for 5 years as [100, 150, 200, 250, 300]. Normalize this reading so that value will transformed from 0-1. (x_norm = (x - min) / (max - min))
    • Write a function incrment_salary that takes current salary and returns increased salary. Hike Rule: <1000 => 20%, 1000-5000 => 10%, >5000 => 5%.
    • Apply incrment_salary to array [800, 1200, 3000, 6000]. Store result as new_salary_ar.