gpt4 book ai didi

Python Jupyter Notebook 无法正确应用函数

转载 作者:行者123 更新时间:2023-12-01 09:32:28 25 4
gpt4 key购买 nike

我有一个 jupyter 笔记本,其中使用逻辑函数返回一个标准化的数组。

代码:

import math
import numpy as np

# takes a list of numbers as input
def logistic_transform(nums):
e = math.e
print(e)
print(nums)
for num in nums:
num = 1 / 1 + (e ** num)
return nums

input = [1, 2, 3]
test = logistic_transform(input)
print(test)

输出为:

2.718281828459045
[1, 2, 3]
[1, 2, 3]

为什么更改没有应用于 input[] 中的值?

最佳答案

只需将您的结果放入另一个列表即可!

import math
import numpy as np
p_num =[]
# takes a list of numbers as input
def logistic_transform(nums):
e = math.e
print('e',e)
print('nums',nums)
for num in nums:
p_num.append(1 / 1 + (e ** num))
return p_num

input = [1, 2, 3]
test = logistic_transform(input)
print('test',test)

e 2.718281828459045

数字[1,2,3]

测试[3.718281828459045、8.389056098930649、21.085536923187664]

关于Python Jupyter Notebook 无法正确应用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49848074/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com