This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients Jim Fasarakis-Hilliard, Jáchym Barvínek, levkivskyi, rhettinger, terry.reedy
Date 2017-04-29.05:04:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1493442296.6.0.171457208215.issue30196@psf.upfronthosting.co.za>
In-reply-to
Content
The '|' should be '&' to avoid useless summing of 0 products.

I think this should be rejected.  Python's number and collections classes provide basic operations from which users can build application-specific functions.  Or in the case of floats, we provide a separate module of specialized functions.  Or in the case of itertools, a section of recipes that build on the basic iterators in the module.

In this case, it makes little sense to me to provide an 'inner product' of Counters (bags, multisets).

>>> a, b, c, d = 'a', 'b', 'c', 'd'
>>> c1 = C([a,a,a,b,b,c])
>>> c2 = C([a, c,c,c, d,d,d])
>>> sum(c1[x]*c2[x] for x in c1.keys() & c2.keys())
6

Even if the keys are counts and one thinks of the counters as sparse vectors, they are not really matrices.  Hence @ does not exactly fit.

If one does want sparse vectors implemented as dicts, they do not always have to be Counters.  A function would not require that.

def sparse_inner_prod(v1, v2):
    return sum(v1[x]*v2[x] for x in v1.keys() & v2.keys())

This only requires that v1 and v2 both have keys and __getitem__ methods.
History
Date User Action Args
2017-04-29 05:04:56terry.reedysetrecipients: + terry.reedy, rhettinger, levkivskyi, Jáchym Barvínek, Jim Fasarakis-Hilliard
2017-04-29 05:04:56terry.reedysetmessageid: <1493442296.6.0.171457208215.issue30196@psf.upfronthosting.co.za>
2017-04-29 05:04:56terry.reedylinkissue30196 messages
2017-04-29 05:04:55terry.reedycreate