Strange accuracy difference between ipython and ipython notebook then using fortran module with f2py

試著忘記壹切 提交于 2019-12-11 02:15:19

问题


I'm encountering a strange accuracy difference between ipython and the ipython notebook when using a fortran module compiled with f2py.

My fortran module is:

subroutine tt(string,fmt,n_num,out)
  implicit none
  INTEGER,INTENT(IN)::n_num
  CHARACTER(LEN=*),INTENT(IN)::string
  CHARACTER(LEN=*),INTENT(IN)::fmt
  DOUBLE PRECISION,INTENT(OUT)::out(n_num)
  read(string,fmt) out
end subroutine tt

Compiling with: f2py -c -m andre tt.f90

In ipython i get:

In [1]: import numpy as np
In [2]: import andre
In [3]: out = np.array(andre.tt(' 0.34 4.56 5.67','(3f5.2)',3),dtype=np.float)
In [4]: print out
    [ 0.34  4.56  5.67]

which is the desired output. However, in the ipython notebook, using the same code, I get:

print out
print out+0.0001
[ 0.  4.  5.]
[  1.00000000e-04   4.00010000e+00   5.00010000e+00]

What am I doing wrong?

来源:https://stackoverflow.com/questions/15834327/strange-accuracy-difference-between-ipython-and-ipython-notebook-then-using-fort

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!