Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Programming course
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
courses
Programming course
Commits
19e8a321
Commit
19e8a321
authored
11 years ago
by
Vermaat
Browse files
Options
Downloads
Patches
Plain Diff
Add some exercises for NumPy
parent
bb67e923
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
numpy.ipynb
+112
-0
112 additions, 0 deletions
numpy.ipynb
with
112 additions
and
0 deletions
numpy.ipynb
+
112
−
0
View file @
19e8a321
...
...
@@ -694,6 +694,31 @@
],
"prompt_number": 19
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can set the seed with `np.random.seed`."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"$\\S$ Exercise: Simple arrays\n",
"===\n",
"\n",
"* Create simple one and two dimensional arrays. First redo the examples, then create your own.\n",
"* Use the functions `len`, `shape` and `ndim` on some of those arrays and observe their output.\n",
"* Experiment with `arange`, `linspace`, `ones`, `zeros`, `eye` and `diag`.\n",
"* Create different kinds of arrays with random numbers.\n",
"* Try setting the seed before creating an array with random values."
]
},
{
"cell_type": "markdown",
"metadata": {
...
...
@@ -1179,6 +1204,93 @@
],
"prompt_number": 3
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"$\\S$ Exercise: Indexing and slicing\n",
"===\n",
"\n",
"* Try the different flavours of slicing, using `start`, `end` and `step`.\n",
"* Verify that the slices in the previous diagram are indeed correct. You may use the following expression to create the array:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"np.arange(6) + np.transpose([np.arange(0, 51, 10)])"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 11,
"text": [
"array([[ 0, 1, 2, 3, 4, 5],\n",
" [10, 11, 12, 13, 14, 15],\n",
" [20, 21, 22, 23, 24, 25],\n",
" [30, 31, 32, 33, 34, 35],\n",
" [40, 41, 42, 43, 44, 45],\n",
" [50, 51, 52, 53, 54, 55]])"
]
}
],
"prompt_number": 11
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"$\\S$ Exercise: Array creation\n",
"===\n",
"\n",
"Create the following arrays (with correct data types):\n",
"\n",
" [[1, 1, 1, 1],\n",
" [1, 1, 1, 1],\n",
" [1, 1, 1, 2],\n",
" [1, 6, 1, 1]]\n",
"\n",
" [[0., 0., 0., 0., 0.],\n",
" [2., 0., 0., 0., 0.],\n",
" [0., 3., 0., 0., 0.],\n",
" [0., 0., 4., 0., 0.],\n",
" [0., 0., 0., 5., 0.],\n",
" [0., 0., 0., 0., 6.]]\n",
"\n",
"Par on course: 3 statements for each (hint: `help(np.diag)`)."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"$\\S$ Exercise: Tiling for array creation\n",
"===\n",
"\n",
"Skim through the documentation for np.tile, and use this function to construct the array:\n",
"\n",
" [[4, 3, 4, 3, 4, 3],\n",
" [2, 1, 2, 1, 2, 1],\n",
" [4, 3, 4, 3, 4, 3],\n",
" [2, 1, 2, 1, 2, 1]]"
]
},
{
"cell_type": "markdown",
"metadata": {
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment