Python numpy: create 2d array of values based on coordinates

前端 未结 5 822
太阳男子
太阳男子 2020-12-24 15:34

I have a file containing 3 columns, where the first two are coordinates (x,y) and the third is a value (z) corresponding to that position. Here\'s a short example:



        
5条回答
  •  北海茫月
    2020-12-24 16:15

    Kezzos beat me to it but I had a similar approach,

    x = np.array([0,0,1,1,2,2])
    y = np.array([1,2,0,1,1,2])
    z = np.array([14,17,15,16,18,13])
    Z = np.zeros((3,3))
    for i,j in enumerate(zip(x,y)): 
        Z[j] = z[i]
    
    Z[np.where(Z==0)] = np.nan
    

提交回复
热议问题