【问题标题】:How to write a simple series in python?如何用python写一个简单的系列?
【发布时间】:2020-03-31 19:03:34
【问题描述】:

我是 python 新手,被赋予了这个任务 - 我需要找到一个系列的总和,但我没有在网上找到任何帮助。任何帮助将不胜感激 - 谢谢。

【问题讨论】:

  • 请提供更多你需要的例子,同时添加你现在得到的。

标签: python series


【解决方案1】:
def squared(numbers):
    return sum(i*i for i in numbers)

【讨论】:

    【解决方案2】:
    numbers = [10,22,33, 54 ] # we declare a list of numbers
    import numpy as np  # we import the library "numpy" and we name it 'np',
    

    它提供了大量的矩阵计算

    np.array(numbers).sum() # here we declace a numpy array and we applicate the sum function
    

    sum(numbers) # this is a simple exemple of using 'sum' function with a simple array
    

    numpy 数组的计算速度非常快,这就是我们使用它的原因

    将 numpy 导入为 np 定义平方(X): y = np.array(X)**2 返回y

    【讨论】:

    • 请添加几句话来解释您的代码在做什么,以便您的回答获得更多的支持。
    • def squared(X): return sum(i*i for i in numbers)
    猜你喜欢
    • 1970-01-01
    • 2013-05-13
    • 1970-01-01
    • 2016-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-19
    • 2021-01-19
    相关资源
    最近更新 更多