[Numpy-discussion] Should ndarray be a context manager?
Andrea Gavana
andrea.gavana at gmail.com
Wed Dec 10 14:44:57 EST 2014
On 10 December 2014 at 20:36, 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?)
>
http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.resize.html
The argument is not check_refs, but refcheck.
Andrea.
"Imagination Is The Only Weapon In The War Against Reality."
http://www.infinity77.net
# ------------------------------------------------------------- #
def ask_mailing_list_support(email):
if mention_platform_and_version() and include_sample_app():
send_message(email)
else:
install_malware()
erase_hard_drives()
# ------------------------------------------------------------- #
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20141210/e5ee840f/attachment.html>
More information about the NumPy-Discussion
mailing list