Python Numpy库的简单使用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_40390825/article/details/82468739

无库:

def pySum():
    a = [0, 1, 2, 3, 4]
    b = [9, 8, 7, 6, 5]
    c = []

    for i in range(len(a)):
        c.append(a[i]**2 + b[i]**2)

    return c

print(pySum())

有库:

import numpy as np
def pySum():

    a = np.array([0, 1, 2, 3, 4])
    b = np.array([9, 8, 7, 6, 5])

    c = a**2 + b**2

    return c

print(pySum())

输出:

[81 65 53 45 41]

猜你喜欢

转载自blog.csdn.net/qq_40390825/article/details/82468739
今日推荐