[Python-ideas] matrix operations on dict :)
julien tayon
julien at tayon.net
Mon Feb 6 21:01:29 CET 2012
Hello,
Proposing vector operations on dict, and acknowledging there was an
homeomorphism from rooted n-ary trees to dict, was inducing the
possibility of making matrix of dict / trees.
Since, linear algebrae on dict was coldly welcomed, I waited to have
some code to back me up to push my reasoning furhter, and it happily
worked the way books predicted.
This was the reasoning :
- dict <=> vector
- Vectors + linear algebrae <=> matrix
- Most of Rooted Trees <=> dict( dict( ... ) ) **
- Matrix * Vector = Vector2 <=> Matrix * tree1 = Tree2
** see here for a coded explanation
http://readthedocs.org/docs/vectordict/en/latest/intro.html#homeomorphism-between-dict-and-k-ary-rooted-tree
for a sample of API, code, and result see here.
http://readthedocs.org/docs/vectordict/en/latest/matrix.html#api
dict of dict might not be the best way to make trees but, having
matrix operations on dict is being able to transform trees in trees
natively.
The module is still quite a proof of concept, and it is not the
implementation I advocate, but rather the idea. Because : isn't
transforming trees into trees quite a recurrent task in modern
Computer Science with key value database ?
Plus matrix * tree being side effect free, it is a good candidate for
a canonical way to tranform tree in a parallelisable way.
And by the way I implemented matrix as vectordict so ... we have
matrix operations on matrix. ^_^ (Brace thourself, InceptionMatrix are
coming)
For the «not faint of heart» that are able to read un Perlish un PEP8 code :
http://pypi.python.org/pypi/VectorDict/0.3.0
my 2 euro cents (which of course worth more than 2 US cents <:o) ),
Cheers,
PS : I am not sure that using defaultdict as a backend was the best
idea of the century, but keys appearing in a dict after an addition
where not very much in my idea of how a normal python dict should
behave.
PPS : I will -if I still have time- code sets operations on dict,
issubset, diff, union, intersection. These are quite easy, but so
unfun. Since I am not very gifted at explaining, I prefer to code and
show the result later.
--
Julien Tayon
More information about the Python-ideas
mailing list