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 linear algebra section #36

Closed
wants to merge 3 commits into from
Closed

Conversation

nickstanisha
Copy link
Collaborator

@nickstanisha nickstanisha commented Feb 20, 2018

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!

Copy link
Collaborator

@davidmascharka davidmascharka left a 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",
Copy link
Collaborator

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",
Copy link
Collaborator

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",
Copy link
Collaborator

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",
Copy link
Collaborator

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",
Copy link
Collaborator

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",
Copy link
Collaborator

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",
Copy link
Collaborator

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",
Copy link
Collaborator

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",
Copy link
Collaborator

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.

@nickstanisha
Copy link
Collaborator Author

@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!

@rsokl
Copy link
Owner

rsokl commented Feb 24, 2019

I need to revisit this after refactoring other numpy material

@rsokl rsokl closed this Feb 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants