Re: [eigen] Reshape function

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


yes this has been discussed a couple of time on the forum, and this
seems reasonable to me.


On Sat, Feb 21, 2009 at 7:27 AM, Keir Mierle <mierle@xxxxxxxxx> wrote:
> It would be nice if Eigen had a reshape function like numpy and matlab:
>
> In [15]: x = random.rand(12)
>
> In [16]: x
> Out[16]:
> array([ 0.98782169,  0.24576577,  0.43955455,  0.54305616,  0.00266062,
>         0.48190312,  0.55144744,  0.36710248,  0.04064906,  0.34286723,
>         0.13652416,  0.01933417])
>
> In [17]: reshape(x, (3, 4))
> Out[17]:
> array([[ 0.98782169,  0.24576577,  0.43955455,  0.54305616],
>        [ 0.00266062,  0.48190312,  0.55144744,  0.36710248],
>        [ 0.04064906,  0.34286723,  0.13652416,  0.01933417]])
>
> In [18]: reshape(x, (6, 2))
> Out[18]:
> array([[ 0.98782169,  0.24576577],
>        [ 0.43955455,  0.54305616],
>        [ 0.00266062,  0.48190312],
>        [ 0.55144744,  0.36710248],
>        [ 0.04064906,  0.34286723],
>        [ 0.13652416,  0.01933417]])
>
> I mail because some of my old libmv1 code used this, and I am porting it to
> libmv2. I use this a fair amount in numpy. Here's what I propose:
>
> Matrix<...> mymatrix(12, 1);
> mymatrix.reshape(3, 4);  // In place.
>
> This should do the same thing as resize, but does not allow changing the
> number of elements, and does not change the contents. I'm not sure what the
> semantics should be around column vs row major; I suspect it's best to not
> do anything fancy (i.e. reshape() with differing row/col major will give
> different results).
>
> Keir
>
>



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/