Practice Problems

Lecture 7

Answer each number in a separate cell

Rename this notebook with your last name and the lecture

ex. CychB_07

Turn-in this notebook on TritonEd by the end of class

  1. Generate arrays
    • Use NumPy to generate an array of integers ranging from 0 up to 360 by intervals of 10.
    • Use NumPy to generate an array from 0 to 2$\pi$ with 36 values (use the numpy attribute pi)
    • print them both out.
    • Use NumPy to generate an array with 20 equally spaced floating point numbers between 0 and 2$\pi$ and print it out.
  2. Array slicing
    • Load the data file Datasets/RecentEarthquakes/earthquakeLocations.txt into a NumPy array. The data file contains the latitude and longitude of 10 different earthquakes.
    • Print out the shape of the array you just imported
    • Convert the shape of the array to 2x10. Use both the .reshape() and .transpose() methods.
    • Print the shape of the two new arrays
    • Take a slice of only the latitudes and assign it in a new variable lats
    • Take a slice of only the longitudes and assign it in a new variable lons.
    • Print the type of the variable lats and lons
    • Convert the new arrays, lats and lons, into separate lists and assign them to new variable names
    • Print the type of these two new variables
    • Save the numpy array lats into a text file labeled 'lats.txt'