使用F2Py编译适合在Python中使用的Fortran例程,下面这段代码成功编译配置gfortran为编译器在使用 F2Py 时,然而,在 Python 中调用时会引发运行时错误!
有什么意见和解决方案吗?
function select(x) result(y)
implicit none
integer,intent(in):: x(:)
integer:: i,j,temp(size(x))
integer,allocatable:: y(:)
j = 0
do i=1,size(x)
if (x(i)/=0) then
j = j+1
temp(j) = x(i)
endif
enddo
allocate(y(j))
y = temp(:j)
end function select
可以找到类似的 StackOverflow 帖子 here .
请您参考如下方法:
看看这篇文章http://www.shocksolution.com/2009/09/f2py-binding-fortran-python/ ,特别是在示例和含义上
!f2py depend(len_a) a, bar
然而,作者并没有涉及生成不同大小的数组的问题。
