Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
NumPy
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== F2PY === Quickly wrap native code for faster scripts.<ref>{{cite web |title=F2PY docs from NumPy |url=https://numpy.org/doc/stable/f2py/usage.html?highlight=f2py |publisher=NumPy |access-date=18 April 2022}}</ref><ref>{{cite web |last1=Worthey |first1=Guy |title=A python vs. Fortran smackdown |url=https://guyworthey.net/2022/01/03/a-python-vs-fortran-smackdown/ |website=Guy Worthey |date=3 January 2022 |publisher=Guy Worthey |access-date=18 April 2022}}</ref><ref>{{cite web |last1=Shell |first1=Scott |title=Writing fast Fortran routines for Python |url=https://sites.engineering.ucsb.edu/~shell/che210d/f2py.pdf |website=UCSB Engineering Department |publisher=University of California, Santa Barbara |access-date=18 April 2022}}</ref> <syntaxhighlight lang="fortran"> ! Python Fortran native code call example ! f2py -c -m foo *.f90 ! Compile Fortran into python named module using intent statements ! Fortran subroutines only not functions--easier than JNI with C wrapper ! requires gfortran and make subroutine ftest(a, b, n, c, d) implicit none integer, intent(in) :: a, b, n integer, intent(out) :: c, d integer :: i c = 0 do i = 1, n c = a + b + c end do d = (c * n) * (-1) end subroutine ftest </syntaxhighlight> <syntaxhighlight lang="pycon"> >>> import numpy as np >>> import foo >>> a = foo.ftest(1, 2, 3) # or c,d = instead of a.c and a.d >>> print(a) (9,-27) >>> help("foo.ftest") # foo.ftest.__doc__ </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)