2.编写函数,求出"1/(1X2)-1/(2X3)+1/(3X4)-1/(4X5)+…"前n项的和,函数以n为参数,它是用户输入的
def sum(n):
r=0
while n>=1:
if n%2==0:
r-=1/(n*(n+1))
else:
r+=1/(n*(n+1))
n-=1
return r
num=int(input("请输入一个整数:"))
p
python代码如下:
import numpy as np
# Write a function that takes as input a list of numbers, and returns
# the list of values given by the softmax function.
def softmax(L):
pass
expL = np.exp(L)
sumExpL = sum(expL)
result = []
for i in expL:
resu