reshape with xyz ordering

Peter Otten __peter__ at web.de
Tue Jul 26 10:59:03 EDT 2016


Heli wrote:

> I sort a file with 4 columns (x,y,z, somevalue) and I sort it using
> numpy.lexsort.
> 
> ind=np.lexsort((val,z,y,x))
> 
> myval=val[ind]
> 
> myval is a 1d numpy array sorted by x,then y, then z and finally val.
> 
> how can I reshape correctly myval so that I get a 3d numpy array
> maintaining the xyz ordering of the data?
> 
> 
> my val looks like the following:
> 
> x,y,z, val
> 0,0,0,val1
> 0,0,1,val2
> 0,0,2,val3
> ...
> 
> Thanks a lot for your help,

I'm not sure I understand the question. Does

shape = [max(t) + 1 for t in [x, y, z]]
cube = myval.reshape(shape)

give what you want?




More information about the Python-list mailing list