Package mekano :: Package atoms :: Module atomvector :: Class AtomVector
[hide private]
[frames] | no frames]

Class AtomVector

object --+
         |
        AtomVector

A dictionary-like object for representing sparse vectors.

Initialization:

>>> a = AtomVector(vec = None, name="")     # vec should support iteritems() returning int:float pairs.
>>> a = AtomVector.fromstring("1:10.0 2:25.0 7:13.0")
>>> a = b.copy()                            # another AtomVector
>>> a.clear()

Iterating (behaves like a defaultdict(float)):

>>> a.iterkeys()
>>> a.iteritems()
>>> for atom in a:
...     print atom

Printing (using an AtomFactory):

>>> a.tostring(af)

Operators:

>>> a + b               # Merges two atomvectors
>>> a * b               # Dot product
>>> a / c               # Element-wise divide (c is a float)

Length-related:

>>> a.Normalize()       # in-place
>>> a.Normalized()      # returns a copy.
>>> a.CosineLeng()
Instance Methods [hide private]
 
CosineLen(...)
 
Normalize(...)
 
Normalized(...)
 
__add__(x, y)
x+y
 
__contains__(x, y)
y in x
 
__delitem__(x, y)
del x[y]
 
__div__(x, y)
x/y
 
__getitem__(x, y)
x[y]
 
__getstate__(...)
 
__iadd__(x, y)
x+y
 
__idiv__(x, y)
x/y
 
__init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
 
__iter__(x)
iter(x)
 
__len__(x)
len(x)
 
__mul__(x, y)
x*y
a new object with type S, a subtype of T
__new__(T, S, ...)
 
__radd__(x, y)
y+x
 
__rdiv__(x, y)
y/x
 
__reduce__(...)
helper for pickle
 
__repr__(x)
repr(x)
 
__rmul__(x, y)
y*x
 
__setitem__(x, i, y)
x[i]=y
 
__setstate__(...)
 
addvector(...)
 
clear(...)
 
contains(...)
 
copy(...)
 
fromstring(...)
 
iteritems(...)
 
iterkeys(...)
 
set(...)
 
tostring(...)
Return a pretty-formatted string.

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __reduce_ex__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]
  name

Inherited from object: __class__

Method Details [hide private]

__init__(...)
(Constructor)

 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Overrides: object.__init__

__new__(T, S, ...)

 
Returns: a new object with type S, a subtype of T
Overrides: object.__new__

__reduce__(...)

 

helper for pickle

Overrides: object.__reduce__
(inherited documentation)

__repr__(x)
(Representation operator)

 

repr(x)

Overrides: object.__repr__

tostring(...)

 

Return a pretty-formatted string.

Parameters:
Returns:
A nicely formatted string, with "..." in case it's too long.