On Mon, Oct 16, 2006 at 02:20:04PM -0600, Charles R Harris wrote:
> Travis,
>
> I note that
>
> >>> a = arange(6).reshape(2,3,order='F')
> >>> a
> array([[0, 1, 2],
> [3, 4, 5]])
>
> Shouldn't that be 3x2? Or maybe [[0,2,4],[1,3,5]]? Reshape is making a copy,
> but flat, flatten, and tostring all show the elements in 'C' order. I ask
> because I wonder if changing the order can be used to prepare arrays for input
> into the LaPack routines.
I think that the calculation of 'a' above is correct, but that the
memory representation is incorrect. For example (see attached script
-- which is overkill, I know), these commands:
x = N.arange(6,dtype=float).reshape((2,3),order='F')
catmem(x)
x = N.array([[0,1,2],[3,4,5]],order='F',dtype=float)
catmem(x)
x = N.array(N.arange(6,dtype=float).reshape((2,3)),order='F')
catmem(x)
x = N.asfortranarray(N.arange(6,dtype=float).reshape((2,3)))
catmem(x)
yield the following results:
0.000000 1.000000 2.000000 3.000000 4.000000 5.000000
0.000000 3.000000 1.000000 4.000000 2.000000 5.000000
0.000000 3.000000 1.000000 4.000000 2.000000 5.000000
0.000000 3.000000 1.000000 4.000000 2.000000 5.000000
Regards
Stéfan
#include <stdio.h>
void catmem(int N, double* p)
{
int i;
for (i = 0; i < N; i++)
printf("%f ", p[i]);
printf("\n");
}
from glob import glob
env = Environment()
env.Replace(CCFLAGS=['-O2','-Wall','-ansi','-pedantic'])
env.SharedLibrary('catmem', ['catmem.c'])
import numpy as N
from ctypes import c_int
import sys
try:
_lib = N.ctypeslib.load_library('libcatmem',__file__)
except OSError:
print "Cannot load libcatmem.so, run 'scons' to compile."
sys.exit(1)
_lib.catmem.restype = None
_lib.catmem.argtypes = [c_int,N.ctypeslib.ndpointer(dtype=N.double)]
def catmem(x):
_lib.catmem(x.size,x)
x = N.arange(6,dtype=float).reshape((2,3),order='F')
catmem(x)
x = N.array([[0,1,2],[3,4,5]],order='F',dtype=float)
catmem(x)
x = N.array(N.arange(6,dtype=float).reshape((2,3)),order='F')
catmem(x)
x = N.asfortranarray(N.arange(6,dtype=float).reshape((2,3)))
catmem(x)
-------------------------------------------------------------------------
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