You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python列表运算报错及暗能量状态方程均值计算问题求助

解决方案:暗能量状态方程绘图中getdist均值计算问题

问题1:均值计算返回NaN且手动过滤后结果异常

getdist的Sample对象有专属的均值计算逻辑,不要直接套用numpy的处理方式:

  • 若要计算派生参数w_DE(z)的均值,先确认该参数已正确添加到样本中,然后用sample.getMeansForNames(['w_DE_z'])(替换为你的参数实际名称),或通过参数索引调用sample.getMeans()[param_index]
  • 出现NaN的常见原因:派生参数计算时部分样本溢出/无效,或样本未去除燃烧期(burn-in)。先清理样本:sample = sample.copy().removeBurnIn(burn_in_fraction=0.2)(根据链长度调整燃烧比例),再计算均值
  • 禁止直接用sample[~np.isnan(derived)]索引,因为getdist的Sample不是普通numpy数组,会破坏样本结构。需手动过滤时,先转成numpy数组处理:
    import numpy as np
    clean_samples = sample.samples[~np.isnan(derived)]
    param_mean = np.mean(clean_samples, axis=0)
    

问题2:(upper-lower)/2.0触发TypeError

upper和lower是Python列表,不支持直接加减运算,需先转为numpy数组:

import numpy as np
upper_arr = np.array(upper)
lower_arr = np.array(lower)
mean_val = (upper_arr - lower_arr) / 2.0

如果upper/lower是getdist输出的置信区间边界,可直接用内置方法获取均值:sample.getMargeStats().mean,无需手动计算。

内容的提问来源于stack exchange,提问作者Trupti Vijay Patil 1910513

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 06:10:31