[Numpy-discussion] problems with multiple outputs with numpy.nditer

George Nurser gnurser@gmail....
Wed Aug 10 05:45:52 CDT 2011


Hi,
I'm running numpy 1.6.1rc2 + python 2.7.1 64-bit from python.org on OSX 10.6.8.

I have a f2py'd fortran routine that inputs and outputs fortran real*8
scalars, and I normally call it like

tu,tv,E,El,IF,HF,HFI = LW.rotate2u(u,v,NN,ff,0)

I now want to call it over 2D arrays UT,VT,N,f

Using steam-age indexing works fine:

mflux_east,mflux_north,IWE,IWE_lin,InvFr,HFroude =
np.empty([6,ny-1,nx],dtype=np.float64)
for j in range(ny-1):
   for i in range(nx):
       u,v,NN,ff = [x[j,i] for x in UT,VT,N,f]
       mflux_east[j,i],mflux_north[j,i],IWE[j,i],IWE_lin[j,i],InvFr[j,i],HFroude[j,i],HFI
= LW.rotate2u(u,v,NN,ff,0)



I decided to try the new nditer option, with

it = np.nditer([UT,VT,N,f,None,None,None,None,None,None,None]
              ,op_flags=4*[['readonly']]+7*[['writeonly','allocate']]
              ,op_dtypes=np.float64)
for (u,v,NN,ff,tu,tv,E,El,IF,HF,HFI) in it:
   tu,tv,E,El,IF,HF,HFI = LW.rotate2u(u,v,NN,ff,0)


Unfortunately this doesn't seem to work. Writing
aa,bb,cc,dd,ee,ff,gg = it.operands[4:]

aa seems to contain the contents of UT (bizarrely rescaled to lie
between 0 and 1), while bb,cc etc are all zero.


I'm not sure whether I've just called it incorrectly, or whether
perhaps it's only supposed to work with one output array.


--George Nurser.


More information about the NumPy-Discussion mailing list