[Numpy-discussion] non-contiguous array error

Robert Kern robert.kern@gmail....
Sun Feb 10 20:04:41 CST 2008

On Feb 10, 2008 7:43 PM, Brad Malone <brad.malone@gmail.com> wrote:
> Hi, I am receiving a "AttributeError: incompatible shape for a
> non-contiguous array" error.  A quick illustration of the type of code
> that gives me the error is shown below:
> --------------------------------------------
> from numpy import *
> list=[i for i in range(0,27)]
> c=array(list)
> c.shape=(3,3,3)
> d=fft.fftn(c)
> d.shape=(27)
> <error here>
> --------------------------------------------
> I suppose this has something to do with the fact that the fourier
> transform of c has imaginary parts, which affects the way the
> information is stored in memory, and this messed up the call to
> .shape?

No. The problem is that "(27)" is not a tuple. Parentheses are also
used for grouping expressions in Python, so a single-element tuple
needs a comma to disambiguate. You want "d.shape = (27,)".

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco

More information about the Numpy-discussion mailing list