Skip to content

Commit

Permalink
Merge pull request #211 from metavee/gh-pages
Browse files Browse the repository at this point in the history
Added challenge to 01-numpy.md regarding slicing a vector vs an array
  • Loading branch information
valentina-s committed Jun 21, 2016
2 parents 5ee3f72 + bf19f35 commit 1a25bbf
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions 01-numpy.md
Original file line number Diff line number Diff line change
Expand Up @@ -737,3 +737,44 @@ the graphs will actually be squeezed together more closely.)
> ## Moving plots around {.challenge}
>
> Modify the program to display the three plots on top of one another instead of side by side.
> ## Stacking arrays {.challenge}
>
> Arrays can be concatenated and stacked on top of one another,
> using NumPy's `vstack` and `hstack` functions for vertical and horizontal stacking, respectively.
>
> ~~~ {.python}
> import numpy
>
> A = numpy.array([[1,2,3], [4,5,6], [7, 8, 9]])
> print('A = ')
> print(A)
>
> B = numpy.hstack([A, A])
> print('B = ')
> print(B)
>
> C = numpy.vstack([A, A])
> print('C = ')
> print(C)
> ~~~
>
> ~~~ {.output}
> A =
> [[1 2 3]
> [4 5 6]
> [7 8 9]]
> B =
> [[1 2 3 1 2 3]
> [4 5 6 4 5 6]
> [7 8 9 7 8 9]]
> C =
> [[1 2 3]
> [4 5 6]
> [7 8 9]
> [1 2 3]
> [4 5 6]
> [7 8 9]]
> ~~~
>
> Write some additional code that slices the first and last columns of `A`, and stacks them into a 3x2 array. Make sure to `print` the results to verify your solution.

0 comments on commit 1a25bbf

Please sign in to comment.