简体   繁体   English

numpy.AxisError:来源:轴 2 超出了维度 2 数组的范围

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

in the code below i want to compute qrad in function of D and L but I think I am misusing the function np.moveaxis causing me to have the following error: numpy.AxisError: source: axis 2 is out of bounds for array of dimension 2 import numpy as np import matplotlib.pyplot as plt在下面的代码中,我想在 D 和 L 的 function 中计算 qrad,但我认为我滥用了 function np.moveaxis,导致出现以下错误:numpy.AxisError: source: axis 2 is out of bounds for array of dimension 2 导入 numpy 作为 np 导入 matplotlib.pyplot 作为 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()

I believe you have two problems.我相信你有两个问题。

When you add 0, 0.032, and 0 to entry in the lists passed to construct a, you are not matching the dimension of the other terms.当您将 0、0.032 和 0 添加到传递给构造 a 的列表中的条目时,您不匹配其他项的维度。 You should use np.zeros(len(l)) and 0.032 * np.ones(len(l)).你应该使用 np.zeros(len(l)) 和 0.032 * np.ones(len(l))。

If my understanding that you want to solve the 3 x 3 system of equations for the 1000 steps in your arange is correct, you want to move the last axis to the front, so for both a and b, move axis -1 to 0. eg "np.moveaxis(a, -1, 0)".如果我理解你想为你的 arange 中的 1000 步求解 3 x 3 方程组是正确的,你想将最后一个轴移到前面,所以对于 a 和 b,将轴 -1 移动到 0。例如“np.moveaxis(a, -1, 0)”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 numpy.AxisError:轴 1 超出维度 1 数组的范围 - numpy 数组 - numpy.AxisError: axis 1 is out of bounds for array of dimension 1 - numpy array 遇到 AxisError:轴 1 超出维度 0 数组的范围 - Encountering AxisError: axis 1 is out of bounds for array of dimension 0 AxisError:轴 1 超出维度 1 数组的范围 - AxisError: axis 1 is out of bounds for array of dimension 1 如何解决 AxisError:轴 1 超出维度 0 数组的范围 - How to solve AxisError: axis 1 is out of bounds for array of dimension 0 np.linalg.norm AxisError:轴 1 超出维度 1 数组的范围 - np.linalg.norm AxisError: axis 1 is out of bounds for array of dimension 1 AxisError:计算类的准确性时,轴 1 超出维度 1 数组的范围 - AxisError: axis 1 is out of bounds for array of dimension 1 when calculating accuracy of classes 2D 数组的 median_absolute_deviation 抛出 AxisError: axis 1 is out of bounds for array of dimension 1 - median_absolute_deviation of 2D array throws AxisError: axis 1 is out of bounds for array of dimension 1 AxisError:计算 roc_auc_score 时,轴 1 超出维度 1 数组的范围 - AxisError: axis 1 is out of bounds for array of dimension 1 when calculating roc_auc_score Numpy 连接给出错误:轴 1 超出维度 1 数组的范围 - Numpy concatenate giving error: axis 1 is out of bounds for array of dimension 1 分类器:轴 1 超出维度 1 数组的范围 - classifier : axis 1 is out of bounds for array of dimension 1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM