简体   繁体   中英

For loop with np.arctan2

i would like to use np.arctan2 in a loop because i have a great number of slices to consider (so i have 3D array), but i have an error : "invalid number of arguments" but i work on 2D array as i use loop...

import numpy as np

Lx=500.
Ly=400.

x0 = Lx/2. 
y0 = Ly/2.

#stockage des valeurs de x0 servant au calcul de x0 optimal
stockx0 = []
for i in range(0,300,1):
    stock = Lx/2. + i
    stockx0.append(stock)

stockx0 = np.array(stockx0)
stockx0 = stockx0[np.newaxis,:]

YA, XA = np.mgrid[0:Ly, 0:Lx]

XA = XA[:, :, np.newaxis]*np.ones((XA.shape[0],XA.shape[1],stockx0.shape[1]))

YA = YA[:, :, np.newaxis]*np.ones((XA.shape[0],XA.shape[1],stockx0.shape[1]))

XA2 = []

for i in range(XA.shape[2]):
    stock = XA[:,:,i] - stockx0[0,i]
    XA2.append(stock)

XA2 = np.array(XA2)

YA = YA - y0

theta_list = []

for i in range(XA2.shape[0]):
      theta = -np.arctan2((YA[:,:,i],XA2[i,:,:]))
      theta_list.append(theta)

theta = np.asarray(theta_list)

numpy.arctan2() expect two arguments, and you're supplying just one (a tuple). You need to remove one pair of parentheses:

theta = -np.arctan2((YA[:,:,i],XA2[i,:,:]))
                    ^--------------------^ THESE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM