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


Groups > comp.lang.python > #111895

Re: reshape with xyz ordering

Path csiph.com!xmission!feeder.awxg.com!aioe.org!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!fu-berlin.de!uni-berlin.de!not-for-mail
From Peter Otten <__peter__@web.de>
Newsgroups comp.lang.python
Subject Re: reshape with xyz ordering
Date Tue, 26 Jul 2016 16:59:03 +0200
Organization None
Lines 32
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>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Trace news.uni-berlin.de gI9D9loLppL8dvtSsvS2QA7HXHHCxNoQPLNG8F8n+KTw==
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'val': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'question.': 0.13; 'columns': 0.16; 'numpy': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.16; 'shape': 0.18; 'sort': 0.25; 'header:User-Agent:1': 0.26; 'header:X-Complaints- To:1': 0.26; 'looks': 0.29; 'array': 0.29; "i'm": 0.30; 'help,': 0.32; 'correctly': 0.34; 'maintaining': 0.34; 'file': 0.34; 'skip:i 20': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'thanks': 0.37; 'received:org': 0.37; 'sure': 0.39; 'does': 0.39; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'received:de': 0.40; 'your': 0.60; 'skip:n 10': 0.62; 'finally': 0.70
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host p57bd8c98.dip0.t-ipconnect.de
User-Agent KNode/4.13.3
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <nn7tro$k2r$1@ger.gmane.org>
X-Mailman-Original-References <fb40329e-c488-4dc9-9786-046fa3bbbe83@googlegroups.com>
Xref csiph.com comp.lang.python:111895

Show key headers only | 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