numpy.AxisError: source: axis 2 is out of bounds for array of dimension 2.

问题描述 投票:0回答:1

在下面的代码中,我想用D和L的函数计算qrad,但我想我误用了函数np.moveaxis,导致我出现以下错误:numpy.AxisError: source: axis 2 is out of bounds for array of dimension 2 import numpy as np import matplotlib.pyplot as plt。

import numpy as np
import matplotlib.pyplot as plt

def plot_with_variating_D ():
    l = np.arange(1, 1.5, 0.0005)
    d = np.arange(0.005, 0.015, 0.00001)
    Eb1 = 3543.75
    A1 = 1
    A2 = np.pi * (d / 2)
    A3 = np.pi
    F11 = 0
    F21 = 2 * (np.arctan(0.5 / l) * (180 / np.pi)) / 360
    F12 = (d * np.pi * F21)
    F12p = (((4 / l ** 2) + 4) ** 0.5 - 2) * (l / 2)
    F13 = F12p - F12
    F14 = 1 - F12 - F13
    F23 = 0.5
    F24 = 1 - F21 - F23
    F34 = F14 / np.pi
    rho = 0.7
    k = 0.04
    pr = 0.7
    cp = 1005
    myu = 2.4 * 10 ** -5
    alpha = 5.68 * 10 ** -5
    beta = 1 / 500
    Ra = (rho * 9.81 * beta * (500 - 293) * l) / (myu * alpha)
    Nu = 0.68 + (0.67 * Ra ** 0.25) / (1 + (0.429 / pr) ** (9 / 16)) ** (4 / 9)
    h = Nu * k
    J1 = 3543.75 + 0.42 * h * (500 - 295)
    a = np.array([[A2*F23,-A2*F23-A1*F13,0], [-0.032-A1*F12-A2*F23,A2*F23,0.032],[A1*F12,A1*F13,0]])
    b = np.array([-A1*F13*J1,-A1*F12*J1,7*(Eb1-J1)/3 +A1*F12*J1+A1*F13*J1])

    print("b=",b)
    x = np.linalg.solve(a,np.moveaxis (b,2,-1))
    x = x.T
    J2 = x[0]
    J3 = x[1]
    J4 = x[2]
    Eb2 = (((1 - 0.8) / (0.8 * A2)) * ((J2 - J1) * A1 * F12 + ((J3 - J2) * A1 * F13 + (J4 - J2) * A1 * F24))) + J2
    qrad = (Eb2 - J2) / ((1 - 0.8) / (0.8 * A2))
    return qrad
plot_with_variating_D()
python python-3.x python-2.7 numpy
1个回答
0
投票

我相信你有两个问题。

当你在传递给构造a的列表中添加0、0.032和0时,你没有匹配其他项的尺寸。你应该使用np.zero(len(l))和0.032 * np.ones(len(l))。

如果我的理解是,你想解决你的arrange中1000步的3×3方程系统是正确的,你想把最后一个轴移到前面,所以对于a和b,把轴-1移到0,例如 "np.moveaxis(a, -1, 0)"。

© www.soinside.com 2019 - 2024. All rights reserved.