Skip to content

Conversation

@itcarroll
Copy link
Contributor

This is my first PR for a Software Carpentry lesson, so please don't hesitate to correct my procedure.

The way I interpreted the challenge, it is necessary for the trainee to avoid removal of singleton dimensions that can result from indexing. I don't think the solution gets ahead of future lessons, but perhaps an maintainer could say?

@valentina-s
Copy link
Contributor

Thank you for the contribution!
Your solution is ok (I suspect the array indexing would look a bit like a magic to a novice, but I do not see much better alternative). Another option is to explain that the stacking functions treat the one dimensional arrays as row vectors, so to obtain the desired result we need

numpy.vstack([A[:,0],A[:,-1]]).T

Unfortunately, I realized transposing has not been introduced in this part yet, so it would require a brief explanation. So if you wish you can add it as an alternative.

@itcarroll
Copy link
Contributor Author

I guess array indexing had only been used with slices in the lesson, so I replaced the A[:, [0]] with the equivalent A[:, :1] and likewise for the last column. That shouldn't be introducing anything new into the challenge solution. (Transposing, as you note, would be a new topic.)

@valentina-s
Copy link
Contributor

I like this solution! Could you just replace the above appearance of A[:,[0]] with A[:,:1], and I will merge.

@valentina-s
Copy link
Contributor

Thanks!

@valentina-s valentina-s merged commit b62eba9 into swcarpentry:gh-pages Nov 10, 2016
@itcarroll itcarroll deleted the 01-challenge-solution branch November 10, 2016 01:46
zkamvar pushed a commit that referenced this pull request Apr 21, 2023
Adds solution to challenge `Stacking Arrays` in episode one
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants