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

array arithmetics vs matrix multiplication #571

Open
thawn opened this Issue Aug 28, 2018 · 6 comments

Comments

Projects
None yet
3 participants
@thawn

thawn commented Aug 28, 2018

In section 01-numpy the following statement deals with array arithmetics:

If, instead of taking an array and doing arithmetic with a single value (as above), you did the arithmetic operation with another array of the same shape, the operation will be done on corresponding elements of the two arrays.

It may be useful to mention that this is different from proper matrix multiplication which can be performed with numpy if you convert the array to a matrix object.

@annefou

This comment has been minimized.

Collaborator

annefou commented Sep 19, 2018

personally I would not mention matrix; I don't think adding matrices would help to understand arrays.

@maxim-belkin

This comment has been minimized.

Collaborator

maxim-belkin commented Sep 19, 2018

I think the point that @thawn is trying to make is that multiplication (*) is element-wise and not a cross product, what might some people expect

import numpy
a = numpy.array([1, 2, 3])
b = numpy.array([4, 5, 6])

a * b # element-wise multiplication
>>> array([ 4, 10, 18])

numpy.cross(a, b) # cross product
>>> array([-3,  6, -3])
@thawn

This comment has been minimized.

thawn commented Sep 20, 2018

@maxim-belkin that's exactly the point I was trying to make. particularly people who are used to MATLAB, where matrix multiplication is the default for two-dimensional arrays, the behaviour of Python may be surprising.

I think one sentence just saying it is not matrix multiplication but element wise multiplication would be sufficient. if you want to be perfect you would also link the words "matrix multiplication" to the documentation of how that works with numpy ;-).

@annefou

This comment has been minimized.

Collaborator

annefou commented Sep 22, 2018

Ok. It sounds good.

Thanks.

@maxim-belkin

This comment has been minimized.

Collaborator

maxim-belkin commented Sep 22, 2018

While difference between element-wise multiplication and cross products is significant, I'm not sure we should talk about it while explaining the material. How about we add a note about element-wise multiplication vs cross product to instructor notes?

@annefou

This comment has been minimized.

Collaborator

annefou commented Sep 23, 2018

Very good idea. So instructors can answer to questions and help to clarify only when needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment