[Numpy-discussion] Should ndarray be a context manager?

Eric Moore ewm at redtetrahedron.org
Wed Dec 10 14:41:17 EST 2014


The second argument is named `refcheck` rather than check_refs.

Eric

On Wed, Dec 10, 2014 at 2:36 PM, Chris Barker <chris.barker at noaa.gov> wrote:

> On Tue, Dec 9, 2014 at 11:03 PM, Sturla Molden <sturla.molden at gmail.com>
> wrote:
>
>> Nathaniel Smith <njs at pobox.com> wrote:
>>
>> > @contextmanager
>> > def tmp_zeros(*args, **kwargs):
>> >     arr = np.zeros(*args, **kwargs)
>> >     try:
>> >         yield arr
>> >     finally:
>> >         arr.resize((0,), check_refs=False)
>>
>> That one is interesting. I have actually never used ndarray.resize(). It
>> did not even occur to me that such an abomination existed :-)
>
>
>  and I thought that it would only work if there were no other references
> to the array, in which case it gets garbage collected anyway, but I see the
> nifty check_refs keyword. However:
>
> In [32]: arr = np.ones((100,100))
>
> In [33]: arr.resize((0,), check_refs=False)
> ---------------------------------------------------------------------------
> TypeError                                 Traceback (most recent call last)
> <ipython-input-33-f0e634534904> in <module>()
> ----> 1 arr.resize((0,), check_refs=False)
>
> TypeError: 'check_refs' is an invalid keyword argument for this function
>
>
> In [34]: np.__version__
> Out[34]: '1.9.1'
>
> Was that just added (or removed?)
>
> -Chris
>
>
> --
>
> Christopher Barker, Ph.D.
> Oceanographer
>
> Emergency Response Division
> NOAA/NOS/OR&R            (206) 526-6959   voice
> 7600 Sand Point Way NE   (206) 526-6329   fax
> Seattle, WA  98115       (206) 526-6317   main reception
>
> Chris.Barker at noaa.gov
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20141210/86635d46/attachment.html>


More information about the NumPy-Discussion mailing list