[Python-ideas] matrix operations on dict :)

julien tayon julien at tayon.net
Tue Feb 7 11:45:04 CET 2012


2012/2/7 Terry Reedy <tjreedy at udel.edu>:
>
> Since your definitions of + and * on dicts does not use order, using the
> terms 'vector' and 'matrix' just seem distracting to me. The only thing you
> are extracting from them is the idea of component-wise operations on
> collections. What is important is whether the operations apply to the
> *values*.

I have checked I can go back and forth without problem. but oky I
forgot the quote in A. I know it may have been disturbing, and I
apologize.


Well, order in actual notation is a commodity for not repeating the
dimension's name.
it's easier to write [ 1 , 2, 3 ] then to always repeat [ x = 1, y =
2, z = 3 ] I am just going back to the basis.

Our disagreement mainly comes from me forgetting the quote in A.


>
> In actual application, the code is likely to be something like:
>  for key,val in source:
>    d.get(key,[]).append(val)
>
It does not propagate recursively though.
so adding d1 =  { 'a' , { 'b' , { 'c' : 1 } , 'd' : 2 } with d2 =   {
'a' , { 'b' , { 'c' : 2 } , 'd' : 1 } wont work with yout example,
but will work with my definition of d1 + d2.


> There are three points here.
> 1. These patterns are specific to subcategories of dicts.
It has sense too for non scalar value, it was  just already tough
trying to explain with scalars, so I limited myself to the simple
case.

> 2. For dicts (and sets and lists), in-place modification is more common than
> creating new dicts (or sets or lists). Python is not mathematics, and it is
> not a functional, side-effect-free language.

I just have to switch a Flag in the matrix operator to make it operate
in place. I was not sure wich option was best.

> 3. The source of modifiers is usually an iterator -- a category rather than
> a class. The iterator does not have to be based on a dict and typically is
> not.

well, you are definitely right on this point.

>
> The same points apply to lists. list1 + list2 is rare compared to
> list1.append(item) and list1.extend(iterable_of_items). And of course, both
> apply to all lists and objects and iterables, rather than specialized
> subcategories.

I also provide an iterator in the form [ ( (path_tovalue), value ), ... ] ^_^

since it does recursive calls, I don't like it, and I try not to make
it too obvious.

Cheers,
Julien



More information about the Python-ideas mailing list