Skip to content

Commit a8c641f

Browse files
committed
DOC: document the change in .base
Forwardport gh-2737.
1 parent 7a0c495 commit a8c641f

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

‎doc/release/1.7.0-notes.rst‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,33 @@ objects. For example the expression (3 and 'test') produces the string
181181
'test', and now np.logical_and(np.array(3, 'O'), np.array('test', 'O'))
182182
produces 'test' as well.
183183

184+
The ``.base`` attribute on ndarrays, which is used on views to ensure that the
185+
underlying array owning the memory is not deallocated prematurely, now
186+
collapses out references when you have a view-of-a-view. For example::
187+
188+
a = np.arange(10)
189+
b = a[1:]
190+
c = b[1:]
191+
192+
In numpy 1.6, ``c.base`` is ``b``, and ``c.base.base`` is ``a``. In numpy 1.7,
193+
``c.base`` is ``a``.
194+
195+
To increase backwards compatibility for software which relies on the old
196+
behaviour of ``.base``, we only 'skip over' objects which have exactly the same
197+
type as the newly created view. This makes a difference if you use ``ndarray``
198+
subclasses. For example, if we have a mix of ``ndarray`` and ``matrix`` objects
199+
which are all views on the same original ``ndarray``::
200+
201+
a = np.arange(10)
202+
b = np.asmatrix(a)
203+
c = b[0, 1:]
204+
d = c[0, 1:]
205+
206+
then ``d.base`` will be ``b``. This is because ``d`` is a ``matrix`` object,
207+
and so the collapsing process only continues so long as it encounters other
208+
``matrix`` objects. It considers ``c``, ``b``, and ``a`` in that order, and
209+
``b`` is the last entry in that list which is a ``matrix`` object.
210+
184211

185212
Deprecations
186213
============

0 commit comments

Comments
 (0)