Convert structured array to regular NumPy array
The simplest method is probably
x.view((float, len(x.dtype.names)))
(float
must generally be replaced by the type of the elements in x
: x.dtype[0]
). This assumes that all the elements have the same type.
This method gives you the regular numpy.ndarray
version in a single step (as opposed to the two steps required by the view(…).reshape(…)
method.
[~]
|5> x = np.array([(1.0, 4.0,), (2.0, -1.0)], dtype=[('f0', '<f8'), ('f1', '<f8')])
[~]
|6> x.view(np.float64).reshape(x.shape + (-1,))
array([[ 1., 4.],
[ 2., -1.]])
np.array(x.tolist())
array([[ 1., 4.],
[ 2., -1.]])
but maybe there is a better method...