8000 DOC: Update numpy4matlab by cooperrc · Pull Request #17159 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@cooperrc
Copy link
Member
@cooperrc cooperrc commented Aug 25, 2020

This PR closes #17094 that requests an update to the "NumPy for MATLAB users" restructured text document.
Comments were integrated from @melissawm, @bjnath, @rossbar, @8bitmp3, and @eric-wieser

Here is a brief list of changes:

  1. Some minor consistencies and grammar were corrected (e.g. Matlab -> MATLAB throughout)
  2. The discussion of array vs matrix was moved to the end of the document, since the general recommendation is to use array
  3. New links were added in the benefits of NumPy including other SciPy/Matplotlib/etc. projects and a link to a wikipedia article with scientific software that uses Python as a scripting language
  4. Some examples in the table were updated and some added e.g. for and if statements were added and random has the updated default_rng recommendation.

@charris charris changed the title Update numpy4matlab: the NumPy for MATLAB users has been updated DOC: Update numpy4matlab Aug 25, 2020
Copy link
Member
@melissawm melissawm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for that @cooperrc ! I left a number of comments, some of them very minor, some only suggestions. One think I'd like to point out is that there are several pieces of Python code in that document non-PEP8 compliant, mainly around slicing and indexing operations.

There are also some places where MATLAB has a registered symbol and other places where it doesn't. Might be worthwile mentioning in the beginning but dropping it for the rest of the text? I'm not sure how that can be done correctly.

I also liked your extra document about creating arrays, and I think it's definitely worth adding. There are also some details to be fixed there (like PEP8 spacing and some wording).

Thanks again for doing this, I know it's a large document with many details but I think this is a very important document for those looking to make the switch.

@bjnath
Copy link
Contributor
bjnath commented Aug 30, 2020

places where MATLAB has a registered symbol and other places where it doesn't

@melissawm Thanks for pointing this out.

Google style guide says

For trademark marking or attribution in documentation, follow any usage guidelines provided by the owners of the respective marks.

MathWorks says

use the relevant trademark symbol to mark the first occurrences

and

The word MATLAB®should appear in all capital letters.

@bjnath
Copy link
Contributor
bjnath commented Aug 30, 2020

I pasted the code in a gist

If you intend it as part of this PR, please go ahead and include it.

@melissawm
Copy link
Member

I pasted the code in a gist

If you intend it as part of this PR, please go ahead and include it.

One option we can consider is splitting this document into two: one more of a "cheatsheet", mostly containing the table currently in this document, and another with more details and examples of how to do things properly in NumPy. This can be considered if the document get too large or if we feel there may be two separate audiences (I suspect that might be the case). But this can be a next step after this PR is merged.

@eric-wieser
Copy link
Member

One option we can consider is splitting this document into two: one more of a "cheatsheet", mostly containing the table currently in this document, and another with more details and examples of how to do things properly in NumPy

I like this idea, especially if cells in the former link to the latter.

Although a single document would work well too now that we have nice sidebar navigation, as long as the table comes first.

@cooperrc
Copy link
Member Author
cooperrc commented Sep 1, 2020

I pasted the code in a gist

If you intend it as part of this PR, please go ahead and include it.

I wasn't sure if it directly closes the issue of updating the current document. It would certainly help a Matlab user, but the original issue was just to update the original document. This would add new material.

What do you think?

@cooperrc
Copy link
Member Author
cooperrc commented Sep 1, 2020

Thanks for that @cooperrc ! I left a number of comments, some of them very minor, some only suggestions. One think I'd like to point out is that there are several pieces of Python code in that document non-PEP8 compliant, mainly around slicing and indexing operations.

Thanks for reviewing and the careful edits. It is very much appreciated!

There are also some places where MATLAB has a registered symbol and other places where it doesn't. Might be worthwile mentioning in the beginning but dropping it for the rest of the text? I'm not sure how that can be done correctly.

@bjnath found the correct way. Thanks!

I also liked your extra document about creating arrays, and I think it's definitely worth adding. There are also some details to be fixed there (like PEP8 spacing and some wording).

I have missed a lot of PEP8 formatting. Thanks for catching those.

Thanks again for doing this, I know it's a large document with many details but I think this is a very important document for those looking to make the switch.

You're very welcome, I agree. This is a document I have referenced many times converting between NumPy and MATLAB. I'm happy to give back.

@cooperrc
Copy link
Member Author
cooperrc commented Sep 1, 2020

I pasted the code in a gist

If you intend it as part of this PR, please go ahead and include it.

One option we can consider is splitting this document into two: one more of a "cheatsheet", mostly containing the table currently in this document, and another with more details and examples of how to do things properly in NumPy. This can be considered if the document get too large or if we feel there may be two separate audiences (I suspect that might be the case). But this can be a next step after this PR is merged.

@melissawm and @eric-wieser I like this idea too. It may even be worthwhile to consider a short tutorial on converting MATLAB to NumPy. We could pick an example that highlights some of the strengths in using NumPy over MATLAB.

One thing that comes to mind is multidimensional arrays. In NumPy, you can nest lists and build N-D arrays (great for continuum mechanics and other tensor-based models), but in Matlab you have to recursively redefine the array to get more dimensions e.g.

A=[1,2;3,4]
A(:,:,2)=[5,6;7,8]

Vs NumPy

A=np.array([[[1,2],[3,4]],
    [[5,6],[7,8]]])

@bjnath
Copy link
Contributor
bjnath commented Sep 1, 2020

@cooperrc It might be worth making a commit now that incorporates @melissawm 's changes so we have a clean base for further review while we think about 2 vs 1.

cooperrc and others added 4 commits September 11, 2020 10:13
update ref for see note HELP L104

Co-authored-by: Melissa Weber Mendonça <melissawm@gmail.com>
update range reference

Co-authored-by: Melissa Weber Mendonça <melissawm@gmail.com>
update Python boolean ref

Co-authored-by: Melissa Weber Mendonça <melissawm@gmail.com>
give link for boolean in the short-circuit logical AND

Co-authored-by: Melissa Weber Mendonça <melissawm@gmail.com>
@cooperrc
Copy link
Member Author
cooperrc commented Sep 11, 2020

@melissawm inspect.getsource vs source - comment

I run into a TypeError if the source code can't be retrieved using inspect.getsource, but when you run np.source you just get a message,

Not available for this object

I'm comparing functions, array and ones in my case.

@eric-wieser
Copy link
Member

@cooperrc, are you referring to np.source? Otherwise, I don't know what source function you're using.

@cooperrc
Copy link
Member Author

@cooperrc, are you referring to np.source? Otherwise, I don't know what source function you're using.

Yes, sorry about that: np.source

cooperrc and others added 13 commits September 11, 2020 11:40
update `source` -> `np.source` L108

Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
update link for boolean

Co-authored-by: Melissa Weber Mendonça <melissawm@gmail.com>
update links for `help` and `np.source` L583

Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
update references to boolean values instead of types

Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
add link to cholesky

Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
add missin `np.` to L360

Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
Co-authored-by: Ben Nathanson <github@bigriver.xyz>
Co-authored-by: Ben Nathanson <github@bigriver.xyz>
incorporate @bjnath edits, nice suggestions

Co-authored-by: Ben Nathanson <github@bigriver.xyz>
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
@cooperrc
Copy link
Member Author

@eric-wieser, @bjnath, and @melissawm I think we hit all of the major changes that needed to go into this update. I'm really happy with this revision, thanks so much for your help!

Can we table any further comments/suggestions and merge the PR? If there are other issues, I can open another PR to continue our discussion (specifically our thoughts on some the finer points on array dimensions in NumPy vs MATLAB).

cooperrc and others added 2 commits September 15, 2020 14:40
revert reference for MathWorks to original -> "The MathWorks, Inc." as seen on website

Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
@mattip mattip merged commit bd26391 into numpy:master Sep 15, 2020
@mattip
Copy link
Member
mattip commented Sep 15, 2020

Thanks @cooperrc and all the reviewers.

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.

Need to update NumPy for Matlab users documentation

7 participants

0