为什么Python的.ravel()不会在数组中保留小数位?

时间:2018-01-25 18:00:06

标签: arrays python-3.x numpy

我的代码的一部分为3D数组中的每个像素构建了正方形邻域,然后通过.ravel()展平。我的3D数组包含3个值:0,0.5和1.但是,当我调用.ravel()时,我丢失了所有0.5个条目,这些条目被转换为0或1(我不知道它们被推到哪个方向)。为什么.ravel()不保留小数信息,是否有解决方法呢?

#the recon array has been initialized with a random distribution of values 0, 0.5, and 1
#recon_size and offset are also predefined, as well as the shape of each Neighborhood array
#I can provide the content for both comments above in an edit if so desired
counter1 = 0
for z in range(recon_size):
    for y in range(recon_size):                       
        for x in range(recon_size):
            xp = x + offset
            yp = y + offset
            zp = z + offset
            #Create a list for the neighborhood centered at this pixel      
            Neighborhood1[counter1,:] = recon_padded[zp,(yp-offset):(yp+offset+1), (xp-offset):(xp+offset+1)].ravel()
            Neighborhood2[counter1,:] = recon_padded[(zp-offset):(zp+offset+1), yp, (xp-offset):(xp+offset+1)].ravel()
            Neighborhood3[counter1,:] = recon_padded[(zp-offset):(zp+offset+1), (yp-offset):(yp+offset+1), xp].ravel()
            counter1 += 1

0 个答案:

没有答案