Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #111895

Re: reshape with xyz ordering

From Peter Otten <__peter__@web.de>
Newsgroups comp.lang.python
Subject Re: reshape with xyz ordering
Date 2016-07-26 16:59 +0200
Organization None
Message-ID <mailman.129.1469545153.22221.python-list@python.org> (permalink)
References <fb40329e-c488-4dc9-9786-046fa3bbbe83@googlegroups.com> <nn7tro$k2r$1@ger.gmane.org>

Show all headers | View raw


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?

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

reshape with xyz ordering Heli <hemla21@gmail.com> - 2016-07-26 07:10 -0700
  Re: reshape with xyz ordering Peter Otten <__peter__@web.de> - 2016-07-26 16:59 +0200
  Re: reshape with xyz ordering Nobody <nobody@nowhere.invalid> - 2016-07-26 23:55 +0100
    Re: reshape with xyz ordering Heli <hemla21@gmail.com> - 2016-07-27 06:01 -0700

csiph-web