ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> numpy-discussion
numpy-discussion
[Numpy-discussion] can't resize ndarray subclass
by Zachary Pincus other posts by this author
Feb 28 2006 4:40AM messages near this date
Re: [Numpy-discussion] Numpy and PEP 343 | Re: [Numpy-discussion] can't resize ndarray subclass
Thus far, it seems like the way to get instances of ndarray  
subclasses is to use the 'view(subclass)' method on a proper ndarray,  
either in the subclass __new__, or after constructing the array.

However, subclass instances so created *do not own their own data*,  
as far as I can tell. They are just "views" on an other array's data.  
This means that these objects can't be resized, or have other  
operations performed on them which requires 'owning' the data buffer.

E.g.:
class f(numpy.ndarray):
   def __new__(cls, *p, **kw):
     return numpy.array(*p, **kw).view(cls)

f([1,2,3]).resize((10,))
    ValueError: cannot resize this array:  it does not own its data
numpy.array([1,2,3]).view(f).resize((10,))
    ValueError: cannot resize this array:  it does not own its data
numpy.array([1,2,3]).resize((10,))
    (no problem)

Is there another way to create ndarray subclasses which do own their  
own data?

Note that numpy.resize(f([1,2,3]), (10,)) works fine. But this isn't  
the same as having an object that owns its data. Specifically,  
there's just no way to have an ndarray subclass resize itself as a  
result of calling a method if that object doesn't own its data.  
(Imagine a variable-resolution polygon type that could interpolate or  
decimate vertices as needed: such a class would need to resize itself.)

Zach




-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@[...].net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion
Thread:
Zachary Pincus
Travis Oliphant
Zachary Pincus
Travis Oliphant
Tim Hochberg
Travis Oliphant
Zachary Pincus
Travis Oliphant
Travis Oliphant

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved