Reputation: 1132
I have the following subroutine in generation.f90
SUBROUTINE generation(t, prob)
IMPLICIT NONE
INTEGER, INTENT(IN) :: t
REAL(8), INTENT(OUT) :: prob
INTEGER :: nT2, c
Do some stuff with t, nT2 and c
prob = nT2/(DBLE(1.0)*c)
END SUBROUTINE generation
I want to use it in Python, so I wrap it with f2py
f2py -c -m generation generation.f90 --fcompiler=gnu95
Then in ipython
I do
from generation import *
a = generation(10000); type(a)
and I get float
. I checked the C file testmodule.c
generated with
f2py generation.f90 -m test
and prob
is type double
. I would like type(a)
to be numpy.float64
. What should I do? I am fairly new to Fortran and f2py.
Upvotes: 1
Views: 2281
Reputation: 75649
As the other answer mentions, Python's float
is already a double-precision number.
However, if you want to convert it, you can use
import numpy as np
a = np.float64(a)
See the numpy documentation for details on conversions.
Upvotes: 2
Reputation: 7198
Floats in python are double precision by default. The harder problem is to get a single-precision float, which requires numpy or some other mathematics package. But in your case, you shouldn't have any concerns.
Upvotes: 1