-
Notifications
You must be signed in to change notification settings - Fork 54
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 linear algebra section #36
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few proofreading comments on a quick read through
">>> np.dot(a, b)\n", | ||
"32\n", | ||
"```\n", | ||
"With an N-D vector `a` and a 1-D vector `b`, the product is computed over the last axis of a.\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
last axis of a
<- code mode
"```\n", | ||
"\n", | ||
"### Matrix multiplication\n", | ||
"The numpy matrix multiplication operator `np.matmul` is unique because it does not operate on arrays of arbitrary dimension. Instead, it prefers to operate on 2-D arrays. Accordingly\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency, NumPy should be stylized
"```\n", | ||
"\n", | ||
"### Matrix multiplication\n", | ||
"The numpy matrix multiplication operator `np.matmul` is unique because it does not operate on arrays of arbitrary dimension. Instead, it prefers to operate on 2-D arrays. Accordingly\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be good to provide examples illustrating each of these cases for clarity
"### Matrix multiplication\n", | ||
"The numpy matrix multiplication operator `np.matmul` is unique because it does not operate on arrays of arbitrary dimension. Instead, it prefers to operate on 2-D arrays. Accordingly\n", | ||
"\n", | ||
"* Arguments to np.matmul cannot be scalars\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code style for np.matmul
" [ 8, 10, 12],\n", | ||
" [12, 15, 18]])\n", | ||
"```\n", | ||
"The @-operator is equivalent to np.matmul and is defined if either argument is a numpy array\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code for np.matmul
and stylize NumPy
"```\n", | ||
"\n", | ||
"### np.einsum\n", | ||
"`np.einsum` is a very powerful tool available in Numpy that uses [**Ein**stein **sum**mation notation](https://en.wikipedia.org/wiki/Einstein_notation), where repeated indices are summed over to compute the final product. For example, you can use Einstein notation to compute a matrix outer product like so\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stylize NumPy
" [ 8, 10, 12],\n", | ||
" [12, 15, 18]])\n", | ||
"```\n", | ||
"It's flexible notation means you can basically perform any arbitrary operation on a pair of numpy arrays. As an example, consider the folling arrays\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's -> Its
Stylize NumPy
">>> b = np.arange(12).reshape(3, 4)\n", | ||
"```\n", | ||
"\n", | ||
"These arrays cannot be broadcast together, so if I want to multiply them together, I need to add a new axis to array `a`.\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'I' should be 'we' for consistency (I think?)
" [24, 27, 30, 33]])\n", | ||
"```\n", | ||
"\n", | ||
"This example can be extended further with operations that take place on the resulting array (e.g. summing over rows and columns in the result).\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing the wording here is up to you, but it sounds weird to me to say "operations that take place on the resulting array." I guess operations would operate on the resulting array but there's got to be better wording than that.
@davidmascharka addressed comments! The only one I didn't fix was adding explicit examples for each matrix multiply case. It's just a lot of examples that are kind of tedious so I think they're better left out. Will defer to you and ryan for that judgement call though! |
I need to revisit this after refactoring other numpy material |
Added a linear algebra section hitting all the points talked about in issue #33 .
I found that there were a ton of edge cases for almost all of these methods and I mentioned almost none of them. I touched on the very basics with np.einsum and directed peopel to this blog which is probably the best description I've found of einsum so far!