[英]Implementing vectors to speed up pitch calculation (numpy.arctan2 and np.sqrt)
[英]For loop with np.arctan2
我想在循环中使用np.arctan2 ,因为我要考虑很多切片(因此我拥有3D数组),但是我遇到了一个错误:“参数数量无效”,但是我使用2D数组环...
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()
两个参数,而您只提供了一个(元组)。 您需要删除一对括号:
theta = -np.arctan2((YA[:,:,i],XA2[i,:,:]))
^--------------------^ THESE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.