Another way to work with the entire array is to use the type 'union' described in the documentation. In your example, you can expand your dtype by adding a "union" field and specifying overlapping "offsets":
from numpy import array, ones, zeros names=['scalar', '1d-array', '2d-array', 'union'] formats=['float64', '(3,)float64', '(2,2)float64', '(8,)float64'] offsets=[0, 8, 32, 0] my_dtype = dict(names=names, formats=formats, offsets=offsets) struct_array3=zeros((4,), dtype=my_dtype)
['union'] now provides access to all data as an array (n,8)
struct_array3['union']
You can work with the "union" or any other fields:
struct_array3['union'] += 2 struct_array3['scalar']= 1
The union field may have another compatible form, for example, '(2,4)float64' . The "string" of such an array might look like this:
array([ (3.0, [0.0, 0.0, 0.0], [[2.0, 2.0], [0.0, 0.0]], [[3.0, 0.0, 0.0, 0.0], [2.0, 2.0, 0.0, 0.0]])], dtype={'names':['scalar','1d-array','2d-array','union'], 'formats':['<f8',('<f8', (3,)),('<f8', (2, 2)),('<f8', (2, 4))], 'offsets':[0,8,32,0], 'itemsize':64})