number exercises

parent 25dff6ea
......@@ -149,7 +149,7 @@ print(np.std(raw))
~~~
{: .output }
> ## Exploring Image Arrays
> ## 2.1. Exploring Image Arrays
>
> * What are the dimensions of the raw and nuclei arrays?
> * What data type are these arrays?
......@@ -203,7 +203,7 @@ array([[156, 173, 156, 161],
~~~
{: .output }
> ## Subsetting a NumPy array
> ## 2.2. Subsetting a NumPy array
>
> Crop the 'raw' image, by removing a border of 500 pixels on all sides.
>
......@@ -266,7 +266,7 @@ print(raw[criteria])
~~~
{: .output }
> ## Masking arrays
> ## 2.3. Masking arrays
>
> The nuclei image contains a binary segmentation i.e.:
>
......@@ -355,7 +355,7 @@ bitsize allows you to store a wider range of values, but will take up more space
always a trade-off between the space it takes up in your computer's memory, and the size of the numbers you want to store.
Note that the size of the values stored in the array has little effect on the memory it takes up i.e. an array of small values but with a large bitsize will still take up a lot of memory.
> ## Working with data types
> ## 2.4. Working with data types
>
> 1. Increase the brightness of the image by 100
> 2. Why does the result look so bizarre? What is going wrong here?
......@@ -943,7 +943,7 @@ Unfortunately, the truncated output
doesn't give us much insight into what these rows describe -
the `geoId` 'JPG11668' isn't particularly informative...
> ## What's going on?
> ## 2.5. What's going on?
>
> Take a look at the names of all the columns in `covid_cases`
> and choose one that gives you a better understanding of where
......@@ -1102,7 +1102,7 @@ print(covid_cases[mask])
~~~
{: .output }
> ## Filtering Practice
> ## 2.6. Filtering Practice
>
> Use what you've learned to find all rows in the `covid_cases`
> dataframe that report cases in the year 2019.
......@@ -1137,7 +1137,7 @@ covid_cases[covid_cases['continentExp'] == 'Europe']['cases'].max()
~~~
{: .output }
> ## Working with Filtered Data
> ## 2.7. Working with Filtered Data
>
> 1. On what date were the most cases reported in Germany so far?
> 2. What was the mean number of cases reported per day in Germany in April 2020?
......@@ -1288,7 +1288,7 @@ Israel 2020-04-02 NaN
~~~
{: .output }
> ## Concatenating Dataframes
> ## 2.8. Concatenating Dataframes
>
> Load in the remaining lockdown data for the other continents
> (America, Europe, and Oceania) and concatenate all these
......@@ -1308,7 +1308,7 @@ Israel 2020-04-02 NaN
> {: .solution }
{: .challenge }
> ## Working with an Indexed Dataframe
> ## 2.9. Working with an Indexed Dataframe
>
> 1. How many rows are in the `covid_lockdowns` dataframe?
> 2. On what date did lockdown begin in Lithuania?
......@@ -1422,7 +1422,7 @@ memory usage: 2.1+ KB
Great! Now neither column is missing any data and
we're almost ready to move onto merging everything into one large dataset.
> ## Practice with Datetime Conversions
> ## 2.10. Practice with Datetime Conversions
>
> Convert the "Start date" and "End date" columns in `covid_lockdowns`
> to datetime format.
......@@ -1501,7 +1501,7 @@ print(combined.head())
~~~
{: .output }
> ## Joined in Hole-y Partnership
> ## 2.11. Joined in Hole-y Partnership
>
> 1. Compare the dimensions of the new `combined` dataframe with those of the original `covid_cases` dataframe. Do they match? If not, investigate `combined`, and the two dataframes from which it was created, to figure out why.
> 2. The `merge` method has a parameter, `join`, which is set to `"inner"` by default. Try out the other possible values (`"outer"`, `"left"`, and `"right"`) and make sure you understand what's going on in each case.
......@@ -1662,7 +1662,7 @@ Name: popData2019, dtype: float64
The example above really shows what split-apply-combine is all about:
we _split_ by continent, _apply_ the `max` method to the values in `popData2019`, and _combine_ the results together into a single object (a Series).
> ## Writing Data to File
> ## 2.12. Writing Data to File
> Earlier, we saw how `pandas.read_csv` can be used to read tabular data from
> a file and create a `DataFrame` object.
> As you might have guessed,
......@@ -1783,7 +1783,7 @@ You're finally ready to calculate the time difference
between the start of lockdown and the peak of rolling mean cases
in each country/territory.
> ## Conquering the Peaks
> ## 2.13. Conquering the Peaks
>
> 1: Fill in the blanks in the code below,
> to create a series, `peak_dates` containing
......
......@@ -73,7 +73,7 @@ END
~~~
{: .output }
> ## Carry the Zero
> ## 4.1. Carry the Zero
>
> - What does `sys.argv[0]` return when you run it in a script?
> - What about in a Jupyter Notebook?
......@@ -113,7 +113,7 @@ TypeError: can only concatenate str (not "int") to str
~~~
{: .output }
> ## Options & Arguments
> ## 4.2. Options & Arguments
> The code block below shows the start of a program
> that takes three input files and returns either
> the product, the sum, or the mean, of the values
......@@ -301,7 +301,7 @@ input_file provided was path/to/input.file
~~~
{: .output }
> ## Adding More Arguments
> ## 4.3. Adding More Arguments
>
> Duplicate [`argparse_example3.py`](../code/argparse_example2.py)
> and add two more arguments to the parser, saving the new version
......@@ -333,7 +333,7 @@ input_file provided was path/to/input.file
> {: .solution}
{: .challenge }
> ## Four's a Crowd
> ## 4.4. Four's a Crowd
>
> What happens when you run
> [`argparse_example4.py`](../code/argparse_example4.py) with four arguments,
......@@ -679,7 +679,7 @@ to `nargs`:
| + | Accept at least one value (values are returned as a list) |
| ? | Accept one or zero values (`default` must also be set if `nargs="?"`)
> ## Handling Multiple Values
> ## 4.5. Handling Multiple Values
>
> Make a copy of [`argparse_example9.py`](../code/argparse_example9.py),
> name it `argparse_example10.py`,
......@@ -910,7 +910,7 @@ optional arguments:
~~~
{: .output }
> ## Parse Master
> ## 4.6. Parse Master
> Using `argparse`, write a script `process_files.py`,
> with an `ArgumentParser` configured such that
> the usage statement below is produced
......@@ -992,7 +992,7 @@ optional arguments:
> providing a more thorough comparison of `argparse`, `docopt` and `click`.
{: .callout }
> ## Options & Arguments Revisited
> ## 4.7 Options & Arguments Revisited
> In an [earlier exercise](#options--arguments),
> you filled in the blanks in code designed to
> parse options and arguments from the command line using `sys.argv`.
......
......@@ -65,7 +65,7 @@ maximising code readability
but some of the tools we'll discuss here
will also identify issues relating to the performance of the code itself.
> ## Words Between the Lines of Age
> ## 5.1. Words Between the Lines of Age
>
> Given an input string and a substring length,
> the function `count_frequencies` returns counts of substrings
......@@ -372,7 +372,7 @@ PEP 8 limits itself to the two most important points:
1. Write docstrings for all modules, functions, classes, and methods that are "public-facing". That is, which might be used by someone else at some point.
2. The closing `"""` of the triple-quoted docstring should be on a line of its own.
> ## Fashions Change. Style is Forever.
> ## 5.2. Fashions Change. Style is Forever.
> Look at the following three code blocks. (Based on [this script][matplotlib-hinton] from the Matplotlib Example Gallery).
>
> **Block A**
......@@ -602,7 +602,7 @@ more about what your options are.
> is still considered a [beta][black-still-beta] product.)
{: .callout }
> ## Comparing Different Code Checkers
> ## 5.3. Comparing Different Code Checkers
> Analyse the code below with `pycodestyle`, `pylint`, and `pyflakes`,
> using default settings in each case.
> (You can download the script [here](code/anagrams.py).)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment