### 2.8. Vector operations

2.8.1. `igraph_vector_add_constant` — Add a constant to the vector.
2.8.2. `igraph_vector_scale` — Multiply all elements of a vector by a constant
2.8.3. `igraph_vector_add` — Add two vectors.
2.8.4. `igraph_vector_sub` — Subtract a vector from another one.
2.8.5. `igraph_vector_mul` — Multiply two vectors.
2.8.6. `igraph_vector_div` — Divide a vector by another one.

#### 2.8.1. `igraph_vector_add_constant` — Add a constant to the vector.

```void igraph_vector_add_constant(igraph_vector_t *v, igraph_real_t plus);
```

`plus` is added to every element of `v`. Note that overflow might happen.

Arguments:

 `v`: The input vector. `plus`: The constant to add.

Time complexity: O(n), the number of elements.

#### 2.8.2. `igraph_vector_scale` — Multiply all elements of a vector by a constant

```void igraph_vector_scale(igraph_vector_t *v, igraph_real_t by);
```

Arguments:

 `v`: The vector. `by`: The constant.

Returns:

 Error code. The current implementation always returns with success.

Time complexity: O(n), the number of elements in a vector.

#### 2.8.3. `igraph_vector_add` — Add two vectors.

```int igraph_vector_add(igraph_vector_t *v1,
const igraph_vector_t *v2);
```

Add the elements of `v2` to `v1`, the result is stored in `v1`. The two vectors must have the same length.

Arguments:

 `v1`: The first vector, the result will be stored here. `v2`: The second vector, its contents will be unchanged.

Returns:

 Error code.

Time complexity: O(n), the number of elements.

#### 2.8.4. `igraph_vector_sub` — Subtract a vector from another one.

```int igraph_vector_sub(igraph_vector_t *v1,
const igraph_vector_t *v2);
```

Substract the elements of `v2` from `v1`, the result is stored in `v1`. The two vectors must have the same length.

Arguments:

 `v1`: The first vector, to subtract from. The result is stored here. `v2`: The vector to subtract, it will be unchanged.

Returns:

 Error code.

Time complexity: O(n), the length of the vectors.

#### 2.8.5. `igraph_vector_mul` — Multiply two vectors.

```int igraph_vector_mul(igraph_vector_t *v1,
const igraph_vector_t *v2);
```

`v1` will be multiplied by `v2`, elementwise. The two vectors must have the same length.

Arguments:

 `v1`: The first vector, the result will be stored here. `v2`: The second vector, it is left unchanged.

Returns:

 Error code.

Time complexity: O(n), the number of elements.

#### 2.8.6. `igraph_vector_div` — Divide a vector by another one.

```int igraph_vector_div(igraph_vector_t *v1,
const igraph_vector_t *v2);
```

`v1` is divided by `v2`, elementwise. They must have the same length. If the base type of the vector can generate divide by zero errors then please make sure that `v2` contains no zero if you want to avoid trouble.

Arguments:

 `v1`: The dividend. The result is also stored here. `v2`: The divisor, it is left unchanged.

Returns:

 Error code.

Time complexity: O(n), the length of the vectors.