summaryrefslogtreecommitdiff
path: root/doc/neps
diff options
context:
space:
mode:
authorPeter Andreas Entschev <peter@entschev.com>2019-08-14 10:08:34 +0200
committerPeter Andreas Entschev <peter@entschev.com>2019-08-14 10:08:34 +0200
commit5195c1bcb91ed9ac337407257d82a78b56be1665 (patch)
treefce31c454f4ea53a25c6b29245587019c6559278 /doc/neps
parentb2785d85e5bd1f594067f4f918d2afaa774ef583 (diff)
downloadnumpy-5195c1bcb91ed9ac337407257d82a78b56be1665.tar.gz
Fix NEP-30 usage example
Diffstat (limited to 'doc/neps')
-rw-r--r--doc/neps/nep-0030-duck-array-protocol.rst14
1 files changed, 6 insertions, 8 deletions
diff --git a/doc/neps/nep-0030-duck-array-protocol.rst b/doc/neps/nep-0030-duck-array-protocol.rst
index c8faebe29..07c4275a1 100644
--- a/doc/neps/nep-0030-duck-array-protocol.rst
+++ b/doc/neps/nep-0030-duck-array-protocol.rst
@@ -107,10 +107,10 @@ An example of how the ``__duckarray__`` protocol could be used to write a
``stack`` function based on ``concatenate``, and its produced outcome, can be
seen below. The example here was chosen not only to demonstrate the usage of
the ``duckarray`` function, but also to demonstrate its dependency on the NumPy
-API, demonstrated by checks on the array's ``ndim`` and ``shape`` attributes.
-Note that the example is merely a simplified version of NumPy's actualy
-implementation of ``stack``, and it is assumed that Dask has implemented the
-``__duckarray__`` method.
+API, demonstrated by checks on the array's ``shape`` attribute. Note that the
+example is merely a simplified version of NumPy's actualy implementation of
+``stack`` working on the first axis, and it is assumed that Dask has implemented
+the ``__duckarray__`` method.
.. code:: python
@@ -121,10 +121,8 @@ implementation of ``stack``, and it is assumed that Dask has implemented the
if len(shapes) != 1:
raise ValueError('all input arrays must have the same shape')
- result_ndim = arrays[0].ndim + 1
-
- expanded_arrays = [arr for arr in arrays]
- return np.concatenate(expanded_arrays)
+ expanded_arrays = [arr[np.newaxis, ...] for arr in arrays]
+ return np.concatenate(expanded_arrays, axis=0)
dask_arr = dask.array.arange(10)
np_arr = np.arange(10)