Suppose I make two recarrays with the same dtype and stack them:
>>> import numpy as np
>>> dt = [('foo', int), ('bar', float)]
>>> a = np.empty(2, dtype=dt).view(np.recarray)
>>> b = np.empty(3, dtype=dt).view(np.recarray)
>>> c = np.hstack((a,b))
Although a
and b
are recarrays, c
is not:
>>> c.foo
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'numpy.ndarray' object has no attribute 'foo'
>>> d = c.view(np.recarray)
>>> d.foo
array([ 0, 111050731618561, 0,
7718048, 8246760947200437872])
I can obviously turn it into a recarray again, as shown with d
above, but that is inconvenient. Is there a reason why stacking two recarrays does not produce another recarray?