I have a set of data that I would like to treat with numpy. The data can be looked at as a set of points in space with an additional property variable that I would like to handle as an object. Depending on a set of data, the vectors may be of length 1, 2, or 3, but is the same length for all points in a given set of data. The property object is a custom class that may be the same for any two given points.
So consider this data as a random example (C and H represent objects that contain atomic properties for Carbon or Hydrogen ... or just some random object). These will not be read in through a file, but created by an algorithm. Here the C object may be the same or it may be different (isotope for example).
Example 3D data set (just abstract representation)
C 1 2 3
C 3 4 5
H 1 1 4
I would like to have a numpy array that contains all of the atomic positions, so that I can perform numpy operations like vector manipulation and such as a translation function def translate(data,vec):return data + vec. I would also like to handle the property objects in parallel. One option would be to have two separate arrays for both, but if I delete an element of one, I would have to explicitly delete the property array value as well. This could get difficult to handle.
I considered using numpy.recarray
x = np.array([(1.0,2,3, "C"), (3.0,2,3, "H")], dtype=[('x', "float64" ),('y',"float6
4"),('z',"float64"), ('type', object)])
But it seems the shape of this array is (2,), which means that each record is handled independently. Also, I cannot seem to understand how to get vector manipulation to work with this type:
def translate(data,vec):return data + vec
translate(x,np.array([1,2,3]))
...
TypeError: unsupported operand type(s) for +: 'numpy.ndarray' and 'numpy.ndarray'
Is numpy.recarray what I should be using? Is there a better way to handle this in a simpler way such that I have a separate numerical matrix of points with a parallel object array that are linked in case an element is removed (np.delete)? I also briefly considered writing an array object that extends ndarray, but I feel like this may be unnecessary and potentially disastrous.
Any thoughts or suggestions would be very helpful.