summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2022-11-08 16:07:43 +0200
committerGitHub <noreply@github.com>2022-11-08 16:07:43 +0200
commit9a6d956b273fe8f4d3ecd1d1f08f8a1c2e4edc06 (patch)
treea10fe27f039c8992cbd7d31dbf6edd4e3fb94c74 /numpy/lib
parent9d11ecd9cce1e91ca0670b602b6fef559961d48a (diff)
parent6fac305a8b62e40aa7a353d4cf72688939c0e0a4 (diff)
downloadnumpy-9a6d956b273fe8f4d3ecd1d1f08f8a1c2e4edc06.tar.gz
Merge pull request #22375 from melissawm/doc-arange
DOC: How to partition domains
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/function_base.py19
-rw-r--r--numpy/lib/index_tricks.py4
2 files changed, 18 insertions, 5 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 6065dd0d3..5f59254b6 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -4953,6 +4953,7 @@ def meshgrid(*xi, copy=True, sparse=False, indexing='xy'):
mgrid : Construct a multi-dimensional "meshgrid" using indexing notation.
ogrid : Construct an open multi-dimensional "meshgrid" using indexing
notation.
+ how-to-index
Examples
--------
@@ -4966,16 +4967,25 @@ def meshgrid(*xi, copy=True, sparse=False, indexing='xy'):
>>> yv
array([[0., 0., 0.],
[1., 1., 1.]])
- >>> xv, yv = np.meshgrid(x, y, sparse=True) # make sparse output arrays
+
+ The result of `meshgrid` is a coordinate grid:
+
+ >>> import matplotlib.pyplot as plt
+ >>> plt.plot(xv, yv, marker='o', color='k', linestyle='none')
+ >>> plt.show()
+
+ You can create sparse output arrays to save memory and computation time.
+
+ >>> xv, yv = np.meshgrid(x, y, sparse=True)
>>> xv
array([[0. , 0.5, 1. ]])
>>> yv
array([[0.],
[1.]])
- `meshgrid` is very useful to evaluate functions on a grid. If the
- function depends on all coordinates, you can use the parameter
- ``sparse=True`` to save memory and computation time.
+ `meshgrid` is very useful to evaluate functions on a grid. If the
+ function depends on all coordinates, both dense and sparse outputs can be
+ used.
>>> x = np.linspace(-5, 5, 101)
>>> y = np.linspace(-5, 5, 101)
@@ -4992,7 +5002,6 @@ def meshgrid(*xi, copy=True, sparse=False, indexing='xy'):
>>> np.array_equal(zz, zs)
True
- >>> import matplotlib.pyplot as plt
>>> h = plt.contourf(x, y, zs)
>>> plt.axis('scaled')
>>> plt.colorbar()
diff --git a/numpy/lib/index_tricks.py b/numpy/lib/index_tricks.py
index 4f414925d..95d5e3ede 100644
--- a/numpy/lib/index_tricks.py
+++ b/numpy/lib/index_tricks.py
@@ -232,7 +232,9 @@ class MGridClass(nd_grid):
--------
lib.index_tricks.nd_grid : class of `ogrid` and `mgrid` objects
ogrid : like mgrid but returns open (not fleshed out) mesh grids
+ meshgrid: return coordinate matrices from coordinate vectors
r_ : array concatenator
+ :ref:`how-to-partition`
Examples
--------
@@ -283,7 +285,9 @@ class OGridClass(nd_grid):
--------
np.lib.index_tricks.nd_grid : class of `ogrid` and `mgrid` objects
mgrid : like `ogrid` but returns dense (or fleshed out) mesh grids
+ meshgrid: return coordinate matrices from coordinate vectors
r_ : array concatenator
+ :ref:`how-to-partition`
Examples
--------