numpy arrays

Heli hemla21 at gmail.com
Thu Apr 7 10:31:58 EDT 2016


Thanks a lot Oscar, 

The lexsort you suggested was the way to go. 

import h5py
import numpy as np
f=np.loadtxt(inputFile,delimiter=None)
xcoord=np.sort(np.unique(f[:,0]))
ycoord=np.sort(np.unique(f[:,1]))
zcoord=np.sort(np.unique(f[:,2]))

x=f[:,0]
y=f[:,1]
z=f[:,2]
val=f[:,3]

ind = np.lexsort((val,z,y,x)) # Sort by x, then by y, then by z, then by val
sortedVal=np.array([(val[i]) for i in ind]).reshape((xcoord.size,ycoord.size,zcoord.size))



More information about the Python-list mailing list