Skip to content

Basic Usage

Declan Valters edited this page Apr 20, 2018 · 1 revision

Creating arrays and accessing elements

#include "tnt.h"
using namespace TNT;


Array2D< double > A(M,N, 0.0);    /* create MxN array; all zeros */

for (i=0; i < M; i++)
   for (j=0; j < N; j++)
       A[i][j] = f(i,j);              /* initalize array values */

Array2D< double > B = A.copy();       /* create a new copy */

Array2D< double > C(B);               /* create a new view of B *
                                      /* Both arrays (B & C) share data */    

Declarations

Array2D< double > A;              /* initalize null (empty) array */
Array2D< double > B(M,N);         /* create an MxN array; uninitalized*/
Array2D< double > C(M,N) = 0.0;   /* create an MxN array; all zeros */

Assignments

A[i][j] = 3.13;                           /* individual element assignment */
A = B;                                    /* shallow array assignment */
A = B.copy();                             /* explicit array copy */
Clone this wiki locally