Re: [f2py] array reference

Pearu Peterson <[email protected]> Thu, 5 Aug 2010 12:02:23 +0300
Newsgroups gmane.comp.python.f2py.user
Message-ID <[email protected]>
On Thu, Aug 5, 2010 at 11:21 AM,  <[email protected]> wrote:
> Hello,
> I have a fortran module which has an array as a global variable.
> After wrapping, and importing my module by python i can acces that variable easily.
>
> In my script, i have code like this:
> #############################################################
> import mymodule
>
> a = mymodule.f2pyinterface.field             #thats my field
> b = a
>
> print (a == mymodule.f2pyinterface.field)    #True!
> print (a is mymodule.f2pyinterface.field)    #False!
> print (a is b)                               #True!
> ###########################################################
> Since my field is very huge i dont want to have two copies of it. My question is:
> Is it possible to assign the reference (and not only the value) of my array to a python variable?

mymodule.f2pyinterface.field is not a copy, it is a view of the Fortran array.
So, no copy is actually made when accessing field.

Pearu