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

如何在Python单个单元格输出f(x)=ln(x)+x²-1的多参数计算结果

Python实现f(x)计算并同单元格输出三个结果的方案

以下两种方案均可在同一单元格内输出三个目标入参的计算结果:

方案1:通过print函数逐个打印

import numpy as np 

def f(x):
    y = np.log(x) + x**2 - 1
    return y 

print(f"f(1.00001) = {f(1.00001)}")
print(f"f(0.5) = {f(0.5)}")
print(f"f(10^-10) = {f(1e-10)}")

方案2:批量计算返回结果集合

适合入参数量多的场景,将计算结果存入列表后直接返回,交互环境会输出完整列表内容:

import numpy as np 

def f(x):
    y = np.log(x) + x**2 - 1
    return y 

x_list = [1.00001, 0.5, 1e-10]
res = [f(x) for x in x_list]
res

内容的提问来源于stack exchange,提问作者CJ1912

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.29 04:06:01