繁体   English   中英

如何解决我的 python 代码(数组和绘图)中的问题?

[英]How could I fix the problem in my python code (array and plot)?

import numpy as np
import matplotlib.pyplot as plt

Pa00 = 100.0  # systemic arterial pressure
Pic00 = 9.5   # intracranial pressure
Pc00 = 25.0   # capillary pressure
Pvs00 = 6.0   # dural sinus pressure
Ca00 = 0.15   # arterial compliance
Rvp = 0.068   # resistance of venous plexus
CBFTo = 10.5 + 2.0   # total CBF of supine state
CBFv = 2.0      # vertebral vein part CBF of supine state
CBFj = CBFTo - CBFv     # jugular vein part CBF of supine state
CVP = 2.0    # central venous pressure
Q_normal = 12.5  # flow rate, ml/sec
unit_R = R_comp * 3.0   # arterial segment resistance
unit_C = 0.1    # arterial segment capacitance

Pvc = np.empty(22, dtype=float)
for i in range(1, 23):
    if i < 10:
        Pvc = Pa00 - i * unit_R * Q_normal
    elif i > 13 & i < 23:
        Pvc = CVP + i * R_comp * CBFj
    elif i == 10:
        Pvc = Pvc[8] - unit_R * Q_normal
        Pvc = Ca00 * (Pvc - Pic00)
    elif i == 11:
        Pvc = Ca00
    elif i == 12:
        Pvc = Pic00
    elif i == 13:
        Pvc = Pvs00
    print("{} {}".format(i, Pvc))
    
plt.plot(i, Pvc)
plt.show()

运行上述代码后,我得到了“打印”的结果。

1 99.95142857142856
2 99.90285714285714
3 99.85428571428571
4 99.80571428571429
5 99.75714285714285
6 99.70857142857143
7 99.66
8 99.61142857142858
9 99.56285714285714
10 2.136
11 2.1496
12 9.5
13 6.0
14 2.1904000000000003
15 2.204
16 2.2176
17 2.2312000000000003
18 2.2448
19 2.2584000000000004
20 2.2720000000000002
21 2.2856000000000005
22 2.2992000000000004

但我无法得到 plot 的结果。 “数组”或“情节”有什么问题吗? 几天来,我陷入了这个问题。

你能告诉我这个问题的解决方案吗?

您实际上是在为 Pvc 变量分配新值,而不是在数组中分配它。 使用Pvc[index] =...将其分配给特定索引。

此外,您需要在数组中记录连续的i值或生成一个新数组(例如np.arange(22) ),否则i将只包含它的最新值(整数)。 在任何情况下,您都可以获得相同的结果,省略 plot function 中的 x-val 数组(例如plt.plot(Pvc)

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM