I have a numpy recarray and want to calculate some statistics. I don't want to use pandas but am looking for a solution using recarray (if there is one).
Is there a way to e.g. calculate the mean of both "columns" without "unwrapping" the "columns" first?
The below throws TypeError: cannot perform reduce with flexible type.
x = np.array([(1.0, 2), (3.0, 4)], dtype=[('x', '<f8'), ('y', '<i8')])
x = x.view(np.recarray)
x.mean() # Error
I could only come up with the below solution.
means = [np.mean(x[rec])for rec in x.dtype.names]
Is there an easier fix?
Thanks for your help!