[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Reshape
From: |
John W. Eaton |
Subject: |
Reshape |
Date: |
Wed, 28 Apr 2010 12:37:25 -0400 |
On 28-Apr-2010, Paul Keir wrote:
| I'm using Octave 3.2.4 under cygwin, and am interested in using the Octave
C++ libraries. I'm using the reshape function on a 2x3 array, but can't see the
effect. My code is:
|
| int main(int argc, char *argv[])
| {
| Array2<double> a(2,3);
|
| for (int i = 0; i < a.dims().length(); i++)
| std::cout << a.dims()(i) << " ";
| std::cout << std::endl;
|
| dim_vector new_shape(1,6);
| a.reshape(new_shape);
|
| for (int i = 0; i < a.dims().length(); i++)
| std::cout << a.dims()(i) << " ";
| std::cout << std::endl;
You can display the dimensions with
dim_vector dv = a.dims ();
std::cout << dv.str () << std::endl;
| return 0;
| }
|
| And the output is:
| 2 3
| 2 3
|
| Am I using reshape wrongly?
Yes, reshape is a const method that returns a new Array object. So
try
Array2<double> b = a.reshape (new_shape);
or
a = a.reshape (new_shape);
jwe
- Reshape, Paul Keir, 2010/04/28
- Reshape,
John W. Eaton <=