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

numpy subject, Exercise 6: why Broadcasting? #2284

Closed
jarmo-seljamaa opened this issue Nov 20, 2023 · 7 comments · Fixed by #2286
Closed

numpy subject, Exercise 6: why Broadcasting? #2284

jarmo-seljamaa opened this issue Nov 20, 2023 · 7 comments · Fixed by #2286
Assignees

Comments

@jarmo-seljamaa
Copy link

jarmo-seljamaa commented Nov 20, 2023

numpy

Exercise 6 is titled "Broadcasting and Slicing" and also there is a note at the end of the exercise referring to a handbook section about broadcasting. While it is a very interesting read, there is little use of that in the exercise.

The task clearly instructs to use slicing only:

Using slicing, output this array:

I imagine the initial array could be created using broadcasting, but it is far more convenient to initialise the array with regular NumPy array creation routines.

@nprimo nprimo self-assigned this Nov 21, 2023
@nprimo
Copy link
Contributor

nprimo commented Nov 21, 2023

Hi @jarmo-seljamaa, thank you for your feedback. I will update the subject (and audit) to make this more relevant to the topic of broadcasting

@nprimo nprimo linked a pull request Nov 21, 2023 that will close this issue
@jarmo-seljamaa
Copy link
Author

Thanks for this. Please wait with the updates for a couple of days. We're in the middle of the piscine and it would be terribly confusing if the tasks change while we're doing them.

@jarmo-seljamaa
Copy link
Author

I'm sorry, I looked at your suggested fix, but adding Using a combination of **slicing** and **broadcasting**, output this array: doesn't make it any clearer on how broadcasting is supposed to be used there. The solution is still a regular numpy array creation with np.ones(). Isn't broadcasting about applying binary ufuncs (e.g., addition, subtraction, multiplication, etc.) on arrays of different sizes?

@nprimo
Copy link
Contributor

nprimo commented Nov 21, 2023

For the first part of the exercise (the creation of the matrix) yes, you can use a simple np.one() call. About the second part of the exercise, you're supposed to create the final matrix as shown on the subject. To achieve the final result, you can use slicing, as the example shown in the audit or a combination of both slicing and broadcasting to perform operations between matrixes that don't share the same shape (only one common dimension)

@jarmo-seljamaa
Copy link
Author

OK, looking at the new example of a possible solution, I'm not sure if it is a good learning example of broadcasting. The previous slicing example was better, imho. But maybe that's just me.

@nprimo
Copy link
Contributor

nprimo commented Nov 21, 2023

Thank you for the feedback! I updated the new version to have an extra question to use broadcasting alone and kept the old questions as they were. We will wait to merge until you all finish with your piscine.

@jarmo-seljamaa
Copy link
Author

jarmo-seljamaa commented Nov 21, 2023

Well, we actually might need sooner merges, because there are too many mistakes, ambiguities etc as you can see from the other tickets I've opened (and we're only on day 2!).

Or at least replies to these tickets to clarify the errors would be appreciated!

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 a pull request may close this issue.

2 participants