diff options
author | Dan Allan <dallan@bnl.gov> | 2019-07-14 10:03:18 -0500 |
---|---|---|
committer | Dan Allan <dallan@bnl.gov> | 2019-07-14 10:03:18 -0500 |
commit | d96618f25db01d814a2159f740cc36e1f355d9d8 (patch) | |
tree | 84038ea8f1f2b3ab344c0748d8b21ad4594a69c1 /doc/source/reference | |
parent | 981103bf709df97ed0c916e45bc1fb0f8aa76666 (diff) | |
download | numpy-d96618f25db01d814a2159f740cc36e1f355d9d8.tar.gz |
Restore old intro, add note at top.
Diffstat (limited to 'doc/source/reference')
-rw-r--r-- | doc/source/reference/arrays.classes.rst | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/doc/source/reference/arrays.classes.rst b/doc/source/reference/arrays.classes.rst index 5d89f2e78..addc403b8 100644 --- a/doc/source/reference/arrays.classes.rst +++ b/doc/source/reference/arrays.classes.rst @@ -6,10 +6,24 @@ Standard array subclasses .. currentmodule:: numpy -Subclassing a ``numpy.ndarray`` is possible but if your goal is to create an -array with *modified* behavior, as do dask arrays for distributed computation -and cupy arrays for GPU-based computation, subclassing is discouraged. Instead, -using numpy's :ref:`dispatch mechanism <basics.dispatch>`_ is recommended. +.. note:: + + Subclassing a ``numpy.ndarray`` is possible but if your goal is to create + an array with *modified* behavior, as do dask arrays for distributed + computation and cupy arrays for GPU-based computation, subclassing is + discouraged. Instead, using numpy's + :ref:`dispatch mechanism <basics.dispatch>` is recommended. + +The :class:`ndarray` can be inherited from (in Python or in C) +if desired. Therefore, it can form a foundation for many useful +classes. Often whether to sub-class the array object or to simply use +the core array component as an internal part of a new class is a +difficult decision, and can be simply a matter of choice. NumPy has +several tools for simplifying how your new object interacts with other +array objects, and so the choice may not be significant in the +end. One way to simplify the question is by asking yourself if the +object you are interested in can be replaced as a single array or does +it really require two or more arrays at its core. Note that :func:`asarray` always returns the base-class ndarray. If you are confident that your use of the array object can handle any |