I'm writing a library that uses NumPy arrays and I have a scalar operation I would like to perform on any dtype. This works fine for most structured arrays, however I run into a problem when creating structured arrays with multiple dimensions for structured elements. As an example,
x = np.zeros(10, np.dtype('3float32,int8'))
print(x.dtype)
print(x.shape)
shows
[('f0', '<f4', (3,)), ('f1', 'i1')]
(10,)
but
x = np.zeros(10, np.dtype('3float32'))
print(x.dtype)
print(x.shape)
yields
float32
(10, 3)
that is, creating a structured array with a single multidimensional field appears to instead expand the array shape. This means that the number of dimensions for the last example is 2, not 1 as I was expecting. Is there anything I'm missing here, or a known workaround?