dtype always copies

Stefan van der Walt stefan at sun.ac.za
Fri Oct 13 09:28:25 CDT 2006


Hi all,

I've noticed that 'astype' always forces a copy.  Is this
behaviour intended?  It seems to conflict with 'asarray', that
tries to avoid a copy.

For example, when wrapping code in ctypes, the following snippet
would have been useful:

def foo(x):
    # ensure x is an array of the right type
    x = N.ascontiguousarray(x).astype(N.intc)

but that will cause a copy, so you'll have to do

def foo(x):
    try:
        x = N.ascontiguousarray(x,N.intc)
    except:
        x = N.ascontiguousarray(x).astype(N.intc)

Maybe I'm missing something obvious here -- any pointers?

Thanks
Stéfan

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642




More information about the Numpy-discussion mailing list