dtype always copies
Charles R Harris
charlesr.harris at gmail.com
Tue Oct 17 14:10:55 CDT 2006
On 10/13/06, Stefan van der Walt <stefan at sun.ac.za> wrote:
>
> 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)
This seems to work now:
In [21]: a
Out[21]:
array([[ 1., 2.],
[ 3., 4.]])
In [22]: ascontiguousarray(a, dtype=int)
Out[22]:
array([[1, 2],
[3, 4]])
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20061017/602d13a4/attachment-0001.html
-------------- next part --------------
-------------------------------------------------------------------------
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
-------------- next part --------------
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion
More information about the Numpy-discussion
mailing list