现在我正在使用f2pyFortran 代码调用 Python 函数。我尝试了一个非常简单的例子,但没有成功。
Fortran90代码:
subroutine foo(fun,r)
external fun
integer ( kind = 4 ) i
real ( kind = 8 ) r
r=0.0D+00
do i= 1,5
r=r+fun(i)
enddo
end
Run Code Online (Sandbox Code Playgroud)
使用命令行:
f2py -c -m 回调callback.f90
Python代码:
import callback
def f(i):
return i * i
print callback.foo(f)
Run Code Online (Sandbox Code Playgroud)
错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: `Required argument 'r' (pos 2) not found`
Run Code Online (Sandbox Code Playgroud) 如何在python中定义全局数组我想将tm和prs定义为全局数组,并在两个函数中使用它们,如何定义它们?
import numpy as np
import matplotlib.pyplot as plt
tm = []
prs = []
def drw_prs_tm(msg):
tm = np.append(tm,t)
prs = np.append(prs,s)
def print_end(msg):
plt.plot(tm,prs,'k-')
Run Code Online (Sandbox Code Playgroud)