[Numpy-discussion] View on sliced array without copy

Jaime Fernández del Río jaime.frio@gmail....
Tue Feb 12 12:25:30 CST 2013


On Tue, Feb 12, 2013 at 9:53 AM, Nicolas Rougier
<Nicolas.Rougier@inria.fr>wrote:

> Did I do something wrong or is it expected behavior ?
>

Try:

print (Z.view('f4'))[:50].base.base is Z # True
print Z[:50].view('f4').base.base is Z   # True

This weird behaviour is fixed in the  just-released numpy 1.7. From the
notes of the release:

The ``.base`` attribute on ndarrays, which is used on views to ensure that
the
underlying array owning the memory is not deallocated prematurely, now
collapses out references when you have a view-of-a-view. For example::

    a = np.arange(10)
    b = a[1:]
    c = b[1:]

In numpy 1.6, ``c.base`` is ``b``, and ``c.base.base`` is ``a``. In numpy
1.7,
``c.base`` is ``a``.

Jaime

-- 
(\__/)
( O.o)
( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus planes
de dominación mundial.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20130212/512eaeb3/attachment.html 


More information about the NumPy-Discussion mailing list