8000 API: Cleaning numpy/__init__.py and main namespace - Part 2 [NEP 52] by mtsokol · Pull Request #24357 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

API: Cleaning numpy/__init__.py and main namespace - Part 2 [NEP 52] #24357

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

Merged
merged 14 commits into from
Aug 12, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
DOC: Adjust constants.rst
  • Loading branch information
mtsokol committed Aug 10, 2023
commit 04dd24dd27d36517660c0c11da6ff94e86f08a72
26 changes: 12 additions & 14 deletions doc/source/reference/constants.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,12 @@ NumPy includes several constants:
Also that positive infinity is not equivalent to negative infinity. But
infinity is equivalent to positive infinity.

`Inf`, `Infinity`, `PINF` and `infty` are aliases for `inf`.

.. rubric:: Examples

>>> np.inf
inf
>>> np.array([1]) / 0.
array([ Inf])
array([inf])


.. data:: nan
Expand Down Expand Up @@ -97,9 +95,9 @@ NumPy includes several constants:
>>> np.nan
nan
>>> np.log(-1)
nan
np.float64(nan)
>>> np.log([-1, 1, 2])
array([ NaN, 0. , 0.69314718])
array([ nan, 0. , 0.69314718])


.. data:: newaxis
Expand All @@ -108,41 +106,41 @@ NumPy includes several constants:

.. rubric:: Examples

>>> newaxis is None
>>> np.newaxis is None
True
>>> x = np.arange(3)
>>> x
array([0, 1, 2])
>>> x[:, newaxis]
>>> x[:, np.newaxis]
array([[0],
[1],
[2]])
>>> x[:, newaxis, newaxis]
>>> x[:, np.newaxis, np.newaxis]
array([[[0]],
[[1]],
[[2]]])
>>> x[:, newaxis] * x
>>> x[:, np.newaxis] * x
array([[0, 0, 0],
[0, 1, 2],
[0, 2, 4]])

Outer product, same as ``outer(x, y)``:

>>> y = np.arange(3, 6)
>>> x[:, newaxis] * y
>>> x[:, np.newaxis] * y
array([[ 0, 0, 0],
[ 3, 4, 5],
[ 6, 8, 10]])

``x[newaxis, :]`` is equivalent to ``x[newaxis]`` and ``x[None]``:
``x[np.newaxis, :]`` is equivalent to ``x[np.newaxis]`` and ``x[None]``:

>>> x[newaxis, :].shape
>>> x[np.newaxis, :].shape
(1, 3)
>>> x[newaxis].shape
>>> x[np.newaxis].shape
(1, 3)
>>> x[None].shape
(1, 3)
>>> x[:, newaxis].shape
>>> x[:, np.newaxis].shape
(3, 1)


Expand Down
0