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
Re: [Numpy-discussion] Numeric memory leak when building Numeric.array from numarray.array
by Francesc Altet other posts by this author
Dec 11 2006 8:47AM messages near this date
Re: [Numpy-discussion] Numeric memory leak when building Numeric.array from numarray.array | Re: [Numpy-discussion] equivalent to isempty command in matlab (newbie question), (Robert Kern)
El dl 11 de 12 del 2006 a les 14:16 +0100, en/na Alexandre Fayolle va
escriure:
>  > > I can work around this by using an intermediate string representation:
>  > > 
>  > > temp = Numeric.fromstring(atest.tostring(), atest.typecode())
>  > > temp.shape = atest.shape
>  > 
>  > Another (faster) workaround would be:
>  > 
>  > temp2 = Numeric.fromstring(atest._data, typecode=atest.typecode())
>  
>  Nice! 

Well, I've to say that this approach only work for contiguous,
non-offseted arrays, as can be seen in:

In [59]:atest = numarray.arange(10)
In [60]:Numeric.fromstring(atest[5:]._data, typecode=atest.typecode())
Out[60]:array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9],'i')  # wrong!
In [61]:Numeric.fromstring(atest[5:].tostring(), atest.typecode())
Out[61]:array([5, 6, 7, 8, 9],'i')                 # good
In [62]:Numeric.fromstring(atest[::2]._data, typecode=atest.typecode())
Out[62]:array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9],'i')  # wrong!
In [63]:Numeric.fromstring(atest[::2].tostring(), atest.typecode())
Out[63]:array([0, 2, 4, 6, 8],'i')                 # good

So, be careful when using it. I'd rather keep using your approach, which
is the faster one that is completely general.

-- 
Francesc Altet    |  Be careful about using the following code --
Carabos Coop. V.  |  I've only proven that it works, 
www.carabos.com   |  I haven't tested it. -- Donald Knuth

_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@[...].org
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Thread:
Alexandre Fayolle
Francesc Altet
Alexandre Fayolle
Francesc Altet

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