Storing Data (Need) Exercises
Exercise 1 (Total recall?) ☻
Purely from memory, jot down:
- Two similarities between lists and arrays.
- Two differences between lists and arrays.
- What is a dictionary?
If you cannot recall the answers, please refer to the course notes and put this information you could not recall in italics.
Exercise 2 (Indexing) ☻
Modify the following code to print out all elements with an odd number. I have done the one corresponding to i9 for you.
Exercise 3 (Index again) ☻
Given the following list in Python:
elements = ['Hydrogen',
'Helium', 'Lithium',
'Beryllium', 'Boron', 'Carbon',
'Nitrogen', 'Oxygen',
'Fluorine',
'Neon']- Access and print the element at index 4 using forward indexing.
- Access and print the element at index 4 from the end of the list using reverse indexing.
Exercise 4 (How many ones) ☻
Use the concepts you learned in this chapter to determine the number of 1’s in the following list of numbers.
numbers=[45, 60, 1, 30, 96, 1, 96, 57, 16, 1,
99, 62, 86, 43, 42, 60, 59, 1, 1, 35,
83, 47, 34, 28, 68, 23, 22, 92, 1, 79,
1, 29, 94, 72, 46, 47, 1, 74, 32, 20,
8, 37, 35, 1, 89, 29, 86, 19, 43, 61] Here are some hints:
- Use a NumPy array.
- Ask a question.
Falseis considered0, andTrueis considered1bysum().
Exercise 5 (A Matter of Statistics) The following shows the data related to \(x_1\) and \(x_2\).
Using NumPy:
- Determine the means of \(x_1\) and \(x_2\).
- Determine the standard deviations of \(x_1\) and \(x_2\).
- Determine the Pearson correlation coefficient \(r\) for the two datasets. Don’t use
np.corrcoef()! - Compare your results to
np.corrcoef().
HINTS: np.mean(), np.std(), np.sum(), np.sqrt()