# Create a CovariantVector¶

## Synopsis¶

Create a CovariantVector

## Results¶

Output:

```v: [1, 2, 3]
```

## Code¶

### C++¶

```#include "itkCovariantVector.h"

int
main(int, char *[])
{
constexpr unsigned int Dimension = 3;
using CoordType = double;

using VectorType = itk::CovariantVector<CoordType, Dimension>;
VectorType v;
v[0] = 1.0;
v[1] = 2.0;
v[2] = 3.0;

std::cout << "v: " << v << std::endl;

return EXIT_SUCCESS;
}
```

### Python¶

```#!/usr/bin/env python

import itk

Dimension = 3
CoordType = itk.D

VectorType = itk.CovariantVector[CoordType, Dimension]

v = VectorType()
v[0] = 1.0
v[1] = 2.0
v[2] = 3.0
print("v: " + str(v))
```

## Classes demonstrated¶

template<typename `T`, unsigned int `NVectorDimension` = 3>
class `CovariantVector` : public itk::FixedArray<T, NVectorDimension>

A templated class holding a n-Dimensional covariant vector.

CovariantVector is a templated class that holds a single vector (i.e., an array of values). CovariantVector can be used as the data type held at each pixel in an Image or at each vertex of an Mesh. The template parameter T can be any data type that behaves like a primitive (or atomic) data type (int, short, float, complex). The NVectorDimension defines the number of components in the vector array.

CovariantVector is not a dynamically extendible array like std::vector. It is intended to be used like a mathematical vector.

If you wish a simpler pixel types, you can use Scalar, which represents a single data value at a pixel. There is also the more complex type ScalarCovariantVector, which supports (for a given pixel) a single scalar value plus an array of vector values. (The scalar and vectors can be of different data type.)

CovariantVector is the type that should be used for representing normals to surfaces and gradients of functions. AffineTransform transform covariant vectors different than vectors.

See

Image

See

Mesh

See

Point

See

Vector

See

Matrix

ITK Sphinx Examples: