为什么输出是n

2024-06-16 09:50:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我想知道为什么y作为数组返回。如果有帮助的话,x是一个numpy数组。你知道吗

我还没有到达必须在数组中存储y值的位置,但我正在尝试找到精细缩放网格上N_obs_photon(t)的平均值,以给出粗略缩放网格上N_obs_photon(t)的平滑图形。我认为带有sum(array)/len(array)的部分应该给我一个float,但是它返回一个数组(更准确地说是1001个数组)。即使我尝试将x设置为只有一个值的数组,y仍然作为数组返回。我该怎么写才能得到y的平均值呢?你知道吗

x = np.linspace(0,1,1001)

ftc = 11
L = 10**(-3)
i = x/L

j = np.arange(0,11001,1) #end number is max(i)*ftc + 1

'''reference:
fine_grid_number = j
coarse_grid_number = i
coase_grid_width = L
fine_grid_width = L/ftc #denominator is ftc 
coarse_grid_position = i*L
fine_grid_position = j*L/ftc #denominator is ftc'''

#Plan is to create an array of y values, then plot x vs y

for n in i:
    q = np.arange(-0.5*(ftc-1),0.5*ftc,1)
    #temp_array = np.empty([])
    temp_array = []
    for w in q:
        t = ftc*n + w #t is fine grid number
        t = t*L/ftc #convert to fine grid position
        if t < 0: #drop t when it would be less than zero
            t = 0
            temp_array.append(t) #add to array
        else:
            t = N_obs_photon(t)   #take through function
            temp_array.append(t) #add to array
    y = sum(temp_array)/len(temp_array) #average the array

    print(y) #test if y is a number

    #store result in y array

Tags: toin网格numberisnpposition数组