我有一个 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/