Python Jupyter Notebook 无法正确应用函数

标签 python jupyter-notebook

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

相关文章:

python - 如何更新 Python?

python - 哨兵自动发现master

Python:将 CSV 文件从一个 RPi 复制到另一个 RPi

python - 如何通过命令行将 IPython Notebook 转换为 Python 文件?

google-drive-api - google colaboratory 不刷新驱动器内容?

jupyter-notebook - 是否可以在 jupyter 笔记本中运行 bokeh 小部件 python 回调

python - 多个 csrftoken cookie,RFC 要求只有 1 个 csrftoken 吗?

Python 程序员 : Learning ruby (for rails)

python - 为什么我无法在 Pycharm 中创建 jupyter Notebook 并正确打开 ipynb?

jupyter-notebook - jupyter notebook 中的原始单元格是什么