[Numpy-discussion] f2py pass by reference

Sameer Grover sameer.grover.1 at gmail.com
Tue Apr 12 14:41:09 EDT 2011

On 12/04/11 23:36, Mathew Yeates wrote:
> I have
> subroutine foo (a)
>        integer a
>        print*, "Hello from Fortran!"
>        print*, "a=",a
>        a=2
>        end
> and from python I want to do
>>>> a=1
>>>> foo(a)
> and I want a's value to now be 2.
> How do I do this?
> Mathew
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

Someone can correct me if I'm wrong but I don't think this is possible 
with integers because they are treated as immuatable types in python. 
You can, however, do this with numpy arrays with "intent(inplace)". For 

subroutine foo(a)
!f2py intent(inplace)::a
       write(*,*) "Hello from Fortran!"
       write(*,*) "a=",a
end subroutine foo

a = np.array([1,2])
#a is now [2,2]

More information about the NumPy-Discussion mailing list