# Examples


# indices


``` python
import numpy as np

from spector import indices

ind = indices([0, 2])
ind
```


    indices([2 0])


``` python
np.array(ind)
```


    array([2, 0])


``` python
1 in ind
```


    False


``` python
ind.add(1)
```


    True


``` python
ind.todense()
```


    array([ True,  True,  True])


``` python
indices.fromdense([True, False, True])
```


    indices([2 0])


# vector


``` python
from spector import vector

vec = vector({0: 1.0, 2: 2.0, 4: 1.0})
vec
```


    vector([4 2 0], [1. 2. 1.])


``` python
np.array(vec)
```


    array([1., 2., 1.])


``` python
vec[2] += 1.0
vec[2]
```


    3.0


``` python
vec.sum()
```


    5.0


``` python
vec.todense()
```


    array([1., 0., 3., 0., 1.])


``` python
vector.fromdense([1, 0, 2, 0, 1])
```


    vector([4 2 0], [1. 2. 1.])


# matrix


``` python
from spector import matrix

mat = matrix({0: {1: 2.0}})
mat
```


    matrix(spector.vector.vector, {0: vector([1], [2.])})


``` python
mat.row, mat.col, mat.data
```


    (array([0]), array([1]), array([2.]))
