[Numpy-discussion] How to call import_array() properly?

Robert Kern robert.kern at gmail.com
Mon Dec 27 14:15:05 EST 2010


On Mon, Dec 27, 2010 at 13:09, Bruce Sherwood <Bruce_Sherwood at ncsu.edu> wrote:
> Thanks for the good suggestion. I now see that it was purely
> historical that import_array was driven (indirectly through
> init_numpy) from the pure Python component of the module rather than
> in the import of the C++ component, and I've changed that. However,
> I'm still curious as to whether there's a more intelligent or elegant
> way to drive import_array than the following code:
>
> #if PY_MAJOR_VERSION >= 3
> int
> init_numpy()
> {
>        import_array();
> }
> #else
> void
> init_numpy()
> {
>        import_array();
> }
> #endif

Just put "import_array();" into initcvisual(). You should not put it
in any other function.

-- 
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