python - 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()
解决方案
推荐阅读
- chocolatey - Chocolatey - 在 packages.config 中带有用户确认的可选包
- android - 如何在喷气背包数据存储中保存收集的经纬度
- java - 如何设置 MeterRegistry 以在 Micrometer.io 上使用 DataDog
- android - 反应原生不启动地铁捆绑器
- ios - 如何在 ios swift 中为 VoiceOver 设置展开和折叠状态?
- python - 'python -m pip install 之间的区别
'和'点安装 ' - firebase - 如何将数据作为子集合添加到firebase颤振中的所有用户文档?
- json - Laravel - 如何从同一控制器中的其他函数传递变量
- node.js - 有没有办法可以将开放遥测跨度导出到普罗米修斯?
- django - Django 电子邮件:是否已建立与 SMTP 服务器的连接?