I am implementing the 3D Vector class in Python. My vector has x, y, and z coordinates (everything floats), and I need to decide how to store this information. I see at least three options here:
1) Make three separate float fields: self.x, self.y, self.z
class Vector: def __init__(self, x, y, z): self.x = x self.y = y self.z = z
2) Make a list, say self.data, with three elements. I can also use a tuple if the objects can be persistent.
class Vector: def __init__(self, x, y, z): self.data = [x,y,z]
3) Create a numpy array, say self.data, with three elements.
import numpy as np class Vector: def __init__(self, x, y, z): self.data = np.array([x,y,z])
For parameters (2) and (3), I could then implement properties and setters to access single coordinates
@property def x(self): return self.data[0]
4) Why not have some redundancy? I could have both a list (or a tuple, or a numpy array), and separate fields x, y and z.
The class is designed to perform general operations, such as addition of vectors, scalar product, cross-product, rotation, etc. These operations must be considered.
Is there a solution I should prefer and why?