Skip to content
Advertisement

Python namedtuples elementwise addition

Is there a more pythonic way to implement elementwise addition for named tuples?

Using this class that inherits from a namedtuple generated class named “Point I can do elementwise addition for this specific named tuple.

JavaScript

If we use this functionality:

JavaScript

The result is:

JavaScript

Is there a more pythonic way to do this in general? Is there a generalized way to do this that can extend elementwise addition to all namedtuple generated objects?

Advertisement

Answer

This is a possible solution:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement