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
DOC: How to partition domains #22375
base: main
Are you sure you want to change the base?
Conversation
complex numbers. | ||
|
||
* Use `numpy.linspace` if you want the endpoint to be included in the result, or | ||
if you are using a non-integer step size. |
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 bit of "why" is missing, maybe something like
if you are using a non-integer step size. | |
if you are using a non-integer step size since floating-point inaccuracies | |
can make ``arange`` results with floating-point numbers confusing. |
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.
Ahh, you have this below. Maybe a "(see below)" instead?
Looks great, thanks. Perhaps a reference to the howto could be added to the SeeAlso sections of the relevant functions? |
array([0, 2, 4, 6, 8]) | ||
|
||
The arguments ``start`` and ``stop`` should be integer or real, but not | ||
complex numbers. |
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.
Maybe we should mention the builtin range
? real
also means floats, but we want to somewhat discourage that, so I wonder if we can rephrase the sentence to do that.
.. _how-to-partition: | ||
|
||
===================================== | ||
How to partition a domain using NumPy |
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.
Maybe a less mathy wording for the title is better? Something in the direction of generate regular spaced numbers using NumPy?
|
||
>>> np.linspace(1+1.j, 4, 5, dtype=np.complex64) | ||
array([1. +1.j , 1.75+0.75j, 2.5 +0.5j , 3.25+0.25j, 4. +0.j ], | ||
dtype=complex64) |
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 suspect linspace is probably commonly confusing due to problem of requiring num=n+1
compared to the division step with endpoint=True
("fencepost error"), just a thought that mentioning that might help (not sure).
`mgrid` and `ogrid`, approximately defined as:: | ||
|
||
mgrid = nd_grid(sparse=False) | ||
ogrid = nd_grid(sparse=True) |
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.
Maybe not mention nd_grid
at all? It seems more of an implementation detail to me.
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.
Yeah I was conflicted here. Will remove
``ogrid`` | ||
--------- | ||
|
||
Similar to ``numpy.mgrid``, ``numpy.ogrid`` returns a ``nd_grid`` instance, but |
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 is such an instance, but lets ignore that fact?
|
||
Similar to ``numpy.mgrid``, ``numpy.ogrid`` returns a ``nd_grid`` instance, but | ||
the result is an *open* multidimensional meshgrid. This means that when it is | ||
indexed, so that only one dimension of each returned array is greater than 1. |
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.
Is the "so that" to much? Might be good to add length of only one dimension
(the "length") to clarify that it is not ndim
. Could also add a sentence saying that this avoids repeating the data and thus saves memory (just another way to say the same thing) – which is often desirable.
Adds a how-to guide on partitioning domains with NumPy. Covers usage of
The main goal of this document is to avoid issues around usage of linspace and arange, but also to elaborate on the usage of all cited functions/tools. This is a first stab at a guide, feedback is appreciated!
Possibly, fixes #9616, #18625, #19670, #17339
Related issues: #18099, #13349, #12715, #2457, #630, #7009