gpt4 book ai didi

python - 使用 np.arctan2 进行循环

转载 作者:太空宇宙 更新时间:2023-11-04 08:59:02 24 4
gpt4 key购买 nike

我想在循环中使用 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

关于python - 使用 np.arctan2 进行循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27363024/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com