[Cython] contiguous array access

Hoyt Koepke hoytak at cs.ubc.ca
Wed Nov 12 02:48:28 CET 2008


Hello,

I'm trying to use the new contiguous array support and I've hit a bit
of a problem.  I'm curious if this is a bug or is intentional.  When I
do

cdef ndarray[float, mode="c"] Xc = X

where X is a 2 dimensional numpy array, it raises an exception:

File "/home/hoytak/workspace/gravimetrics/spatial/gravity.pyx", line
101, in spatial.gravity._setGFFromSamples (spatial/gravity.c:1242)
    cdef ndarray[float, mode="c"] Xc = X
ValueError: Buffer has wrong number of dimensions (expected 1, got 2)

However, doing

cdef ndarray[float, mode="c"] Xc = X.reshape(-1)

seems to work fine.  If this behavior is intentional, what's the best
way of using contiguous mode with 2+ dim arrays?

Thanks!!!
--Hoyt


++++++++++++++++++++++++++++++++++++++++++++++++
+ Hoyt Koepke
+ University of Washington Department of Statistics
+ http://www.stat.washington.edu/~hoytak/
+ hoytak at gmail.com
++++++++++++++++++++++++++++++++++++++++++


More information about the Cython-dev mailing list