[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Vectorizing loops
From: |
Jordi Gutiérrez Hermoso |
Subject: |
Re: Vectorizing loops |
Date: |
Sat, 5 Nov 2011 14:54:32 -0400 |
On 5 November 2011 02:57, andrewcd <address@hidden> wrote:
> I'm relatively new to working with large datasets, and I need to break the
> habit of doing everything in loops. I'd appreciate if you all could help me
> with one example to get me started.
>
> I have a 260x260x8 matrix. The top row is x coordinates, the first column
> is y coordinates, the depth dimension is time. I want to get the matrix
> into the following format so that I can do panel data regressions:
>
> x1 y1 t1 val
> x1 y1 t2 val
> x1 y2 t1 val
> x1 y2 t2 val
> x2 y1 t1 val
> x2 y1 t2 val
Try the reshape function. Indexing a 3d array with 2 indices can also
work, e.g. try x(2,:) on a 3d array.
HTH,
- Jordi G. H.