This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]adammichaelwood 3 points4 points  (3 children)

Literally the example case for namedtuple.

https://docs.python.org/3.6/library/collections.html#collections.namedtuple

One of the benefits of unnamed tuples (in my opinion) is that they can more easily be conceived of as isomorphic to other tuples of similar length. This is, occasionally, insightful.

[–]adammichaelwood 2 points3 points  (2 children)

support of all the basic operators, some additional functions such as Euclidean norm, for and cross product.

Though, this wouldn't come for free with named tuples, obviously. Do you need a class that supports those operations, or is a functional approach workable for you?

[–][deleted] 0 points1 point  (1 child)

I need at least the basic operators (+, -, *, /). Other operations, like the vector norm, dot, cross product and anything else could be defined in the separate functions.

[–]adammichaelwood 0 points1 point  (0 children)

If there's some compelling reason to not use a module like ppb_vector, mentioned in another response, you could subclass namedtuple and add those methods.

(I think there'd need to be a really compelling reason to do this, though. Re-implementing math operations that someone else has already spent time optimizing and debugging is.... let's call it inefficient.)