I’m working with xyz vectors a lot in my program. I’m using them enough that giving each one a variable (such as offset_x, offset_y, etc) is becoming tedious and cluttering code-wise. Now, I could put each set of x, y, and into tupples (such as offset = (x,y,z) ) , But I’ve found that doing stuff like offset[0] everywhere makes the code not quite as readable as I would like, Using a dict seems too inefficient. Numpy is another option, a lot of people have suggested it, but based on information found at Poor numpy.cross() performance , Nunpy may not be quite as suitable for the short arrays I’m dealing with, and I don’t have much margin for parts of my script slowing down, as some pieces are run several times a second. Is there anything out there that’s both efficient and readable?
Share
Check out namedtuple if you’re looking for a more readable tuple. Points are the example given in the docs.
If you’re interested in efficiency, checkout the implementation. It uses
__slots__and it’s assembled usingexecso it should be minimal overhead vs. a regular tuple.Since it’s coded in Python you could cut out a few of the possibly unnecessary methods like
__repr__,_asdict,_replace, and__getnewargs__to reduce the footprint even more.