For循环索引错误导致错误

时间:2020-04-19 21:18:40

标签: python numpy for-loop indexing

在下面的代码中,我收到一个索引错误,但无法弄清楚。有什么想法是错误的,或者将来有什么技巧可以解决这类错误?应该根据idx1为r和apothem取正确的值,但最终结果不正确。

c = np.linspace(0.01, 1, 10)
for ratio_shear in c:
s = 1
xlist = np.linspace(4, 18, 8)
ylist = np.linspace(0.01, 1, 100)
n, ratio_beams = np.meshgrid(xlist, ylist)
theta = 30

b = ratio_shear * s / 2
a = b / (np.sin(np.radians(theta)))
d_b = ratio_beams * s
alpha = 360 / n
L_s = (s / (np.sin(np.radians(theta))))
L_b = (2 * s) / (np.tan(np.radians(theta)))
p = 1  # loads applied to hierarchical beams
f = 1  # loads applied to one beam
K = 1
E = 1  # Young's Modulus
A_c = ((1 / 4) * np.pi) * (((s / (np.sin(np.pi / n))) + d_b) ** 2)

r = (s / (2 * (np.sin((np.pi / n)))))
apothem = s / (2 * np.tan(np.radians(180 / n)))

restrict = d_b + (2 * a)
mask = np.less_equal(s, restrict)

AreaFil = n * (0.25 * np.pi * (d_b ** 2))
AreaFil[mask] = np.nan
Area1beam = AreaFil / n
AreaShear = n * (np.pi * b ** 2)
AreaShear[mask] = np.nan
Area1shear = AreaShear / n
AreaElli = (np.pi * a * b) * n
AreaElli[mask] = np.nan

r = (s / (2 * (np.sin((np.pi / n)))))
apothem = s / (2 * np.tan(np.radians(180 / n)))

LIbSum = np.empty((len(xlist)))
LIsSum = np.empty((len(xlist)))

for idx1 in range(len(xlist)):
    LIb = np.empty((int((2 * idx1) + 4)))
    LIs = np.empty((int((2 * idx1) + 4)))
    for idx2 in range(1, int(5 + (2*idx1))):
        LIb[idx2 - 1]: abs((r[idx1]) * (np.cos(((np.radians(alpha[idx1] / 2)) + ((idx2 - 1) * (np.radians(alpha[idx1])))))))
        LIs[idx2 - 1]: abs((apothem[idx1]) * (np.cos(((idx2 - 1) * (np.radians(alpha[idx1]))))))
    LIbSquared = LIb ** 2
    LIsSquared = LIs ** 2
    LIbSum[idx1] = np.sum(LIbSquared)
    LIsSum[idx1] = np.sum(LIsSquared)

0 个答案:

没有答案