首页 > 解决方案 > ValueError:x 和 y 必须具有相同的第一维,但具有形状 (23,) 和 (1,)

问题描述

我正在尝试使用预定义的 eta 数组来绘制 theta 与 eta 来计算 theta。我不断收到错误消息:ValueError:x 和 y 必须具有相同的第一维,但具有形状 (23,) 和 (1,)。我究竟做错了什么?

import numpy as np

# Definition of the array of eta for plotting
eta = np.array([0, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4, 1.6, 1.8, 2, 2.2, 2.6, 3, 3.4, 3.8, 4.2, 4.6, 5.0, 5.6, 6.2, 7.0, 8.0])
 
# Function to generate theta
def func_theta(eta, Pr):
   fdoubleprime=np.array([0.33206, 0.33199, 0.33147, 0.33008, 0.32739, 0.32301, 0.31659, 0.30787, 0.29667, 0.28293, 0.26675, 0.24835, 0.20646, 0.16136, 0.11788, 0.08013, 0.05052, 0.02948, 0.01591, 0.00543, 0.00155, 0.00022, 0.00001])
   g=fdoubleprime**Pr
   num=0.0
   for i in range(len(eta)-1):
       num+=0.5*((eta[i+1]-eta[i]) * (g[i+1]+g[i]))
   den=0.0
   for j in range(22):
       den+=0.5*((eta[j+1]-eta[j]) * (g[j+1]+g[j]))
   theta= 1-num/den   
    
   return (theta)

import matplotlib.pyplot as plt
fig = plt.figure(1, figsize=(4,3))
plt.plot(eta, func_theta(eta, 0.5), color='black')

plt.xlabel('$\\eta$')
plt.ylabel('$\\theta$')

plt.text(2, 0.4, 'Pr=0.5')
plt.text(1.5, 0.3, '0.8')

plt.xlim(0, 4)
plt.ylim(0, 1)
plt.grid()

标签: pythonnumpy

解决方案


推荐阅读