On 10/13/06, Stefan van der Walt <[EMAIL PROTECTED]> wrote:
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
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
------------------------------------------------------------------------- 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
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion