In [1]:
Copied!
import numpy as np
from spector import indices
ind = indices([0, 2])
ind
import numpy as np
from spector import indices
ind = indices([0, 2])
ind
Out[1]:
indices([2 0])
In [2]:
Copied!
np.array(ind)
np.array(ind)
Out[2]:
array([2, 0])
In [3]:
Copied!
1 in ind
1 in ind
Out[3]:
False
In [4]:
Copied!
ind.add(1)
ind.add(1)
Out[4]:
True
In [5]:
Copied!
ind.todense()
ind.todense()
Out[5]:
array([ True, True, True])
In [6]:
Copied!
indices.fromdense([True, False, True])
indices.fromdense([True, False, True])
Out[6]:
indices([2 0])
vector¶
In [7]:
Copied!
from spector import vector
vec = vector({0: 1.0, 2: 2.0, 4: 1.0})
vec
from spector import vector
vec = vector({0: 1.0, 2: 2.0, 4: 1.0})
vec
Out[7]:
vector([4 2 0], [1. 2. 1.])
In [8]:
Copied!
np.array(vec)
np.array(vec)
Out[8]:
array([1., 2., 1.])
In [9]:
Copied!
vec[2] += 1.0
vec[2]
vec[2] += 1.0
vec[2]
Out[9]:
3.0
In [10]:
Copied!
vec.sum()
vec.sum()
Out[10]:
5.0
In [11]:
Copied!
vec.todense()
vec.todense()
Out[11]:
array([1., 0., 3., 0., 1.])
In [12]:
Copied!
vector.fromdense([1, 0, 2, 0, 1])
vector.fromdense([1, 0, 2, 0, 1])
Out[12]:
vector([4 2 0], [1. 2. 1.])
matrix¶
In [13]:
Copied!
from spector import matrix
mat = matrix({0: {1: 2.0}})
mat
from spector import matrix
mat = matrix({0: {1: 2.0}})
mat
Out[13]:
matrix(spector.vector.vector, {0: vector([1], [2.])})
In [14]:
Copied!
mat.row, mat.col, mat.data
mat.row, mat.col, mat.data
Out[14]:
(array([0]), array([1]), array([2.]))