python函数返回值几个_从Python函数保存多个返回值

这段代码定义了一个名为`id_match`的函数,它接收五个参数并返回四个值。函数根据输入条件筛选数据并计算匹配项的频率。然后,通过一个for循环,使用不同的`zmin`, `zmax`和`mlim`值调用该函数六次。现在,博主想要将每次调用的输出结果存储到一个数组中,以便进一步保存为CSV文件。通常,可以使用列表来存储这些输出,最后将列表转换为DataFrame并写入CSV。
摘要由CSDN通过智能技术生成

我有一个函数,在进行一些计算后返回4个值。我给出5个参数作为输入。

我使用6个不同的输入参数运行上述函数6次,以获得6个不同的输出。在def id_match(zcosmo,zphot,zmin,zmax,mlim):

data_zcosmo_lastz = zcosmo[(data_m200>mlim)*(zcosmo>zmin)*(zcosmo

data_zphot_lastz = zphot[(data_m200>mlim)*(zphot>zmin)*(zphot

halo_id_zcosmo = data_halo_id[(data_m200>mlim)*(zcosmo>zmin)*(zcosmo

halo_id_zphot = data_halo_id[(data_m200>mlim)*(zphot>zmin)*(zphot

idrep_zcosmo = data_idrep[(data_m200>mlim)*(zcosmo>zmin)*(zcosmo

idrep_zphot = data_idrep[(data_m200>mlim)*(zphot>zmin)*(zphot

file2freq1 = Counter(zip(halo_id_zcosmo,idrep_zcosmo))

file2freq2 = Counter(zip(halo_id_zphot,idrep_zphot))

set_a = len(set(file2freq1) & set(file2freq2)) # this has the number of common objects

difference = 100.0 - (set_a*100.0)/len(data_zcosmo_lastz)

print difference

return (len(data_zcosmo_lastz),len(data_zphot_lastz),set_a,difference)

zmin_limits = [0.1,0.4,0.7,1.0,1.3,1.6]

zmax_limits = [0.4,0.7,1.0,1.3,1.6,2.1]

mlim_limits = [5e13,5e13,5e13,5e13,5e13,5e13]

for a,b,c in zip(zmin_limits,zmax_limits,mlim_limits):

id_match(data_zcosmo_lastz,data_zphot_lastz,a,b,c)

上面的代码为6个不同的输入参数打印difference。在

但我想知道如何将函数的输出保存到数组中,以便将其保存为csv file???

我知道

a,b,c,d = id_match(input params)

将给予a,b,c,d以获得{}的其中一个输出。但我希望将所有返回值存储在一个数组中。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值