Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added challenge to 01-numpy.md regarding slicing a vector vs an array #211

Merged
merged 2 commits into from
Jun 21, 2016
Merged
Changes from 1 commit
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
19 changes: 19 additions & 0 deletions 01-numpy.md
Original file line number Diff line number Diff line change
Expand Up @@ -703,3 +703,22 @@ 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.

> ## Converting between an array and a vector {.challenge}
>
> In some cases in NumPy, an vector of size N behaves differently than an Nx1 array.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this challenge really explains how it might behave differently, or why that might even be a problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. In my experience, it generally results in strange-looking broadcasting errors.

Perhaps I could reformat this as a small code fragment that results in such an error, and the challenge would be to fix the error. Do you think that would work better?

> The vector will have a shape (N,), while the array will have a shape (N,1).
>
> The code below generates a 5x5 array of random numbers `A`,
> then uses slices to extract the last column of `A` as a vector with shape (5,) and store it in `b`.
>
> Modify it so that `b` is an array with shape (5,1).
>
> ~~~ {.python}
> import numpy
>
> A = numpy.random.random([5,5]) # array of random numbers
> b = A[:,-1] # take the last column from A
>
> print(b.shape)
> ~~~