[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: reshape implementation ?
From: |
Jaroslav Hajek |
Subject: |
Re: reshape implementation ? |
Date: |
Thu, 25 Nov 2010 22:14:58 +0100 |
On Wed, Nov 24, 2010 at 12:01 PM, CdeMills <address@hidden> wrote:
>
> Hello,
>
> the next problem I'm facing is about reshape. Context:
> x=dataframe(randn(3, 3))
> Dataframe with 3 rows and 3 columns
> _ X1 X2 X3
> Nr double double double
> 1 -0.106705 -0.77947 0.68085
> 2 0.048692 -0.76935 -0.90692
> 3 -1.675128 0.84691 1.16656
>
> %#Using matrix conversion:
> repmat(mean(x(:,:)), [3 1])
> ans =
>
> -0.57771 -0.23397 0.31350
> -0.57771 -0.23397 0.31350
> -0.57771 -0.23397 0.31350
>
> repmat(mean(x), [3 1])
> => error. It goes around line 72 of reshape.m
> m = rows (a); n = columns (a);
> p = idx(1); q = idx(2);
> x = reshape (a, m, 1, n, 1); => !
> reshape: can't reshape 1x1 array to 1x1x3 array
> I looked into octave sources; the message is emitted in liboctave/Array.cc,
> from the code
> template <class T>
> Array<T>::Array (const Array<T>& a, octave_idx_type nr, octave_idx_type nc)
> : rep (a.rep), dimensions (nr, nc),
> slice_data (a.slice_data), slice_len (a.slice_len)
> {
> if (dimensions.safe_numel () != a.numel ())
> {
> std::string dimensions_str = a.dimensions.str ();
> std::string new_dims_str = dimensions.str ();
> (*current_liboctave_error_handler)
> ("reshape: can't reshape %s array to %s array",
> dimensions_str.c_str (), new_dims_str.c_str ());
> }
> ...
>
> How does it come that the argument is a dataframe of size 1x3, yet it is
> identified as 1x1 array ? There are overloaded rows, colums, numel and size
> function for dataframe.
>
I think you'll have to overload reshape for dataframe.