Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Michael Selik Newsgroups: comp.lang.python Subject: Re: reshape and keep x,y,z ordering Date: Tue, 07 Jun 2016 13:16:37 +0000 Lines: 33 Message-ID: References: <5ef3691e-2317-41df-ad60-3d2450841413@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de YdEEcmFxwG75DcTs90RnMAMvH+9yGzTRFI01kAyrJhjQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'array.': 0.07; 'column': 0.07; 'assumed': 0.09; 'anyway': 0.11; '>>>': 0.15; '2016': 0.16; '2],': 0.16; 'numpy': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'row': 0.16; 'skip:n 50': 0.16; 'x,y,z': 0.16; 'wrote:': 0.16; 'email addr:gmail.com>': 0.18; '>>>': 0.20; 'to:2**1': 0.21; 'skip:n 60': 0.22; 'header:In-Reply-To:1': 0.24; 'question': 0.27; 'message-id:@mail.gmail.com': 0.27; 'specify': 0.27; 'follows': 0.29; 'array': 0.29; 'you?': 0.30; 'normally': 0.30; 'tue,': 0.34; 'this?': 0.34; 'received:google.com': 0.35; 'but': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'cases': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'received:209': 0.38; 'received:209.85.220': 0.38; 'goes': 0.39; 'data': 0.39; 'does': 0.39; 'to:addr:python.org': 0.40; 'hello,': 0.40; 'more': 0.63; 'subject:,': 0.82; 'subject:keep': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=H6mXE7GQ29ANJr7TjAvnsBjbGyOcJp3RkKSfIa8ktcs=; b=cI0u3Bn628RLi0wPZhE19CnEUH8Rx37dTN0sU8XGjTYgaQu43D7OkgT32axN7AAUvl aqFC+ks7kEO/gHOsOcAn3HlkUIOUfLrbGLtfB/b3hEg0s0cdAbYCteQWJ9RLZjyabVhg W/wc8pthftvf5argaAzLFNtVy6hz2YKKM0+DSvxyl3g+PfqHUVWvS7/tZipwQsHur9aM wH/4/L8iD7IFpOKZN1sG9TIJhPjWTqa/FIWAmDvS5072xlGnYg3ft0G4jukKUKAYWrdQ XzN5PY74FS8n3aa4C38DQFoj7zx9Iowbkt5hr0cSp6Q1iqAo0rCOrro9AUEVP/TBYBdA M2Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=H6mXE7GQ29ANJr7TjAvnsBjbGyOcJp3RkKSfIa8ktcs=; b=hEFq5gVkqh2O6+X/f2kHJ+nCCvcD2De6zbp9xHGgi+mPmp5J2Bap3eFEQOMs3E4BP3 qEcvieUm0RLA5tEqk1rDnz2F97bLx7G48nnMXHBG9J5IdJmQsonv9p5ctr3uwY8OugG+ r67mtSt7ufog8ZkHAut7vk/KFKVpd1dKadFMHYA1UNC9TGyxxFAmCHUkphfqrrfaHtSa Zv6RxDrX9JZ7axv6ZqqWxRzHJxyyYy/U2rURIoJKietdyX/8P8ZffMr3QZjHbHVrul9S fMW3E44aacQQr2L9oYyYrSMCmdjb5CETHsA0ZVOERd2x6kRi+K9D27FUw9fXbQnYd8nn ZC3g== X-Gm-Message-State: ALyK8tLMh3VKR39lJ6eJ8/UKZewJyXhV06+uRo7wLWss8UO8FchOgoL0EqVeeQldefWiQTvCNn0qQkLCCzff2w== X-Received: by 10.55.145.67 with SMTP id t64mr20975273qkd.96.1465305407569; Tue, 07 Jun 2016 06:16:47 -0700 (PDT) In-Reply-To: <5ef3691e-2317-41df-ad60-3d2450841413@googlegroups.com> X-Content-Filtered-By: Mailman/MimeDel 2.1.22 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <5ef3691e-2317-41df-ad60-3d2450841413@googlegroups.com> Xref: csiph.com comp.lang.python:109626 On Tue, Jun 7, 2016 at 7:31 AM Heli wrote: > Hello, > I have a question regarding reshaping numpy array. > > I either have a 1D array that I need to reshape to a 3D array or a 3D > array to reshape to a 1d numpy array. > > In both of these cases it is assumed that data follows x,y,z ordering. > and I use the following to reshape the numpy array. > > new_1d_array=np.reshape(3d.transpose(),(3d_nx*3d_ny*3d_nz,)) > > new_3d_array=np.reshape(1d,((3d_x,3d_y,3d_z)).transpose()) > > My question is if there is anyway that reshape would keep x,y,z ordering > that would not require transpose? and if there is a better more efficient > way to do this? >>> a = np.arange(9).reshape(3,3) >>> a array([[0, 1, 2], [3, 4, 5], [6, 7, 8]]) >>> a.flatten() array([0, 1, 2, 3, 4, 5, 6, 7, 8]) >>> a.flatten('F') array([0, 3, 6, 1, 4, 7, 2, 5, 8]) Does this work for you? The flatten method normally goes row by row, but you can specify FORTRAN style column by column flattening.