Skip to content
This repository has been archived by the owner on Jan 3, 2018. It is now read-only.

Add challenge on NumPy array slicing #893

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions novice/python/01-numpy.ipynb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"metadata": {
"name": "",
"signature": "sha256:bdd5075bd4a75df8ed67c3124b0664471edfc1bfe6110ddcf01e68e156bcb9bb"
"signature": "sha256:67ffce7b022a7f2572764219cdd5dbe7d15f23c592c70db42b60d8e0aba56f40"
},
"nbformat": 3,
"nbformat_minor": 0,
Expand Down Expand Up @@ -1247,7 +1247,38 @@
" i.e., a string that contains no characters.\n",
" If `data` holds our array of patient data,\n",
" what does `data[3:3, 4:4]` produce?\n",
" What about `data[3:3, :]`?"
" What about `data[3:3, :]`?\n",
" \n",
"1. For the NumPy array displayed by `print integer_data`\n",
"\n",
" `[[ 0 2 4 6 8 10 12 14 16 18]\n",
" [ 1 3 5 7 9 11 13 15 17 19]\n",
" [ 2 4 6 8 10 12 14 16 18 20]\n",
" [ 3 5 7 9 11 13 15 17 19 21]\n",
" [ 4 6 8 10 12 14 16 18 20 22]\n",
" [ 5 7 9 11 13 15 17 19 21 23]\n",
" [ 6 8 10 12 14 16 18 20 22 24]\n",
" [ 7 9 11 13 15 17 19 21 23 25]\n",
" [ 8 10 12 14 16 18 20 22 24 26]\n",
" [ 9 11 13 15 17 19 21 23 25 27]]`\n",
"\n",
" what does `print integer_data[2:4, 3:5]` produce?\n",
" \n",
" 1. `[[ 8 10 12]\n",
" [ 9 11 13]\n",
" [10 12 14]]`\n",
" \n",
" 1. `[[ 5 7]\n",
" [ 6 8]]`\n",
" \n",
" 1. `[[ 7 9]\n",
" [ 8 10]]`\n",
" \n",
" 1. `[[ 8 10]\n",
" [ 9 11]]`\n",
" \n",
" 1. `[[12 14]\n",
" [13 15]]`"
]
},
{
Expand Down
35 changes: 30 additions & 5 deletions novice/python/01-numpy.md
Original file line number Diff line number Diff line change
Expand Up @@ -562,11 +562,36 @@ last three characters: gen
Given those answers,
explain what `element[1:-1]` does.

1. The expression `element[3:3]` produces an [empty string](../../gloss.html#empty-string),
i.e., a string that contains no characters.
If `data` holds our array of patient data,
what does `data[3:3, 4:4]` produce?
What about `data[3:3, :]`?
1. For the NumPy array displayed by `print integer_data`

`[[ 0 2 4 6 8 10 12 14 16 18]
[ 1 3 5 7 9 11 13 15 17 19]
[ 2 4 6 8 10 12 14 16 18 20]
[ 3 5 7 9 11 13 15 17 19 21]
[ 4 6 8 10 12 14 16 18 20 22]
[ 5 7 9 11 13 15 17 19 21 23]
[ 6 8 10 12 14 16 18 20 22 24]
[ 7 9 11 13 15 17 19 21 23 25]
[ 8 10 12 14 16 18 20 22 24 26]
[ 9 11 13 15 17 19 21 23 25 27]]`

what does `print integer_data[2:4, 3:5]` produce?

1. `[[ 8 10 12]
[ 9 11 13]
[10 12 14]]`

1. `[[ 5 7]
[ 6 8]]`

1. `[[ 7 9]
[ 8 10]]`

1. `[[ 8 10]
[ 9 11]]`

1. `[[12 14]
[13 15]]`
</div>

### Plotting
Expand Down