help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Reshape


From: Paul Keir
Subject: RE: Reshape
Date: Thu, 29 Apr 2010 09:42:55 +0100

Many thanks.

-----Original Message-----
From: John W. Eaton [mailto:address@hidden
Sent: 28 April 2010 17:37
To: Paul Keir
Cc: address@hidden
Subject: Reshape

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

The University of Glasgow, charity number SC004401



reply via email to

[Prev in Thread] Current Thread [Next in Thread]