为什么输出不是浮点数

时间:2018-06-03 23:30:36

标签: python arrays python-3.x numpy

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

我还没有得到我必须在数组中存储y值的位,但是我试图在精细缩放的网格上找到N_obs_photon(t)的平均值来进行平滑处理在粗略缩放的网格上N_obs_photon(t)的图形。我认为sum(array)/len(array)的部分应该给我一个浮点数,而是返回一个数组(更正确的是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

0 个答案:

没有答案
相关问题