🌐
NumPy
numpy.org › doc › stable › user › basics.rec.html
Structured arrays — NumPy v2.5 Manual
The simplest way to assign values to a structured array is using python tuples. Each assigned value should be a tuple of length equal to the number of fields in the array, and not a list or array as these will trigger numpy’s broadcasting rules.
🌐
Python Data Science Handbook
jakevdp.github.io › PythonDataScienceHandbook › 02.09-structured-data-numpy.html
Structured Data: NumPy's Structured Arrays | Python Data Science Handbook
But this is a bit clumsy. There's nothing here that tells us that the three arrays are related; it would be more natural if we could use a single structure to store all of this data. NumPy can handle this through structured arrays, which are arrays with compound data types.
🌐
NumPy
numpy.org › doc › 1.13 › user › basics.rec.html
Structured arrays — NumPy v1.13 Manual
Record arrays are structured arrays wrapped using a subclass of ndarray, numpy.recarray, which allows field access by attribute on the array object, and record arrays also use a special datatype, numpy.record, which allows field access by attribute on the individual elements of the array.
🌐
NumPy
numpy.org › devdocs › user › basics.rec.html
Structured arrays — NumPy v2.6.dev0 Manual
The simplest way to assign values to a structured array is using python tuples. Each assigned value should be a tuple of length equal to the number of fields in the array, and not a list or array as these will trigger numpy’s broadcasting rules.
🌐
TutorialsPoint
tutorialspoint.com › structured-array-in-numpy
NumPy - Creating Structured Arrays
We then create the array with data matching this structure and print the resulting structured array − · import numpy as np # Define the dtype with field names and data types dtype = [('name', 'U10'), ('age', 'i4'), ('height', 'f4')] # Create data consistent with the dtype data = [('Alice', 30, 5.6), ('Bob', 25, 5.8), ('Charlie', 35, 5.9)] # Create the structured array structured_array = np.array(data, dtype=dtype) print("Structured Array:\n", structured_array)
🌐
TutorialsPoint
tutorialspoint.com › numpy › numpy_structured_arrays.htm
NumPy - Structured Arrays
In the following example, we are defining a structured array with fields for "name", "age", and "height" using a specified dtype. We then create this array with corresponding data − · import numpy as np # Define the dtype dtype = [('name', 'U10'), ('age', 'i4'), ('height', 'f4')] # Define the data data = [('Alice', 30, 5.6), ('Bob', 25, 5.8), ('Charlie', 35, 5.9)] # Create the structured array structured_array = np.array(data, dtype=dtype) print("Structured Array:\n", structured_array)
🌐
Medium
medium.com › @aamernabi › structured-array-and-masked-arrays-in-numpy-ce779991b939
Structured Arrays and Masked Arrays in NumPy | by Aamer Paul | Medium
July 29, 2025 - Structured arrays provide a way to work with heterogeneous data in a uniform and efficient manner. In the following example, we have NumPy Structured Array named users with three elements, each representing a user.
🌐
NumPy
numpy.org › doc › 1.22 › user › basics.rec.html
Structured arrays — NumPy v1.22 Manual
The simplest way to assign values to a structured array is using python tuples. Each assigned value should be a tuple of length equal to the number of fields in the array, and not a list or array as these will trigger numpy’s broadcasting rules.
Find elsewhere
🌐
Finxter
blog.finxter.com › numpy-structured-arrays-and-record-arrays
NumPy Structured Arrays and Record Arrays – Be on the Right Side of Change
November 6, 2020 - >>> struct_arr[0] = tuple(Alice_info) >>> struct_arr[1] = tuple(Chris_info) >>> struct_arr[2] = tuple(Bob_info) >>> struct_arr[3] = tuple(Priyatham_info) >>> struct_arr array([('Alice', 42, False), ('Chris', 29, True), ('Bob', 42, False), ('Priyatham', 25, True)], dtype=[('person_names', '<U9'), ('person_ages', '<i8'), ('is_python_programmer', '?')]) By following any of the two ways of assignment, Structured Arrays gets filled with our information. This can be interpreted and visualized as, Now we can access any element that’s present anywhere in the array very efficiently. We get an added advantage of Structured data type along with normal NumPy array features like aggregations, broadcasting, etc.
🌐
NumPy
numpy.org › doc › 2.1 › user › basics.rec.html
Structured arrays — NumPy v2.1 Manual
The simplest way to assign values to a structured array is using python tuples. Each assigned value should be a tuple of length equal to the number of fields in the array, and not a list or array as these will trigger numpy’s broadcasting rules.
🌐
SciPy
docs.scipy.org › doc › numpy-1.14.0 › user › basics.rec.html
Structured arrays — NumPy v1.14 Manual
The simplest way to assign values to a structured array is using python tuples. Each assigned value should be a tuple of length equal to the number of fields in the array, and not a list or array as these will trigger numpy’s broadcasting rules.
🌐
Spark Code Hub
sparkcodehub.com › numpy › advanced › structured arrays
Mastering Structured Arrays in NumPy: Advanced Data ...
Structured arrays in NumPy are arrays that allow each element to be a record with multiple named fields, each with its own data type. Think of them as a lightweight alternative to a database table or a pandas DataFrame, but with the performance ...
🌐
CSE Department
cse.poriyaan.in › topic › structured-arrays-50614
Structured Arrays - Python Libraries for Data Wrangling
• A structured Numpy array is an array of structures. As numpy arrays are homogeneous i.e. they can contain data of same type only.
🌐
Medium
medium.com › @mitchparker99 › numpy-structured-arrays-43a08f4de81a
Numpy: Structured Arrays. Structured arrays are ndarrays whose… | by Mitchell Parker | Medium
June 19, 2024 - Numpy: Structured Arrays Structured arrays are ndarrays whose datatype is composed of simpler datatypes organized as a sequence of named fields. For example: x = np.array([('Rex', 9, 81.0), ('Fido' …
🌐
SciPy
docs.scipy.org › doc › numpy-1.10.1 › user › basics.rec.html
Structured arrays — NumPy v1.10 Manual
Record arrays are structured arrays wrapped using a subclass of ndarray, numpy.recarray, which allows field access by attribute on the array object, and record arrays also use a special datatype, numpy.record, which allows field access by attribute on the individual elements of the array.
🌐
LabEx
labex.io › tutorials › python-structured-arrays-in-numpy-85704
Structured Arrays in NumPy | Programming Tutorials | LabEx
We can index a structured array with multiple fields by passing a list of field names. This will return a new structured array containing only the specified fields.
🌐
Sling Academy
slingacademy.com › article › working-with-structured-arrays-in-numpy
Working with structured arrays in NumPy (with examples) - Sling Academy
This tutorial explores structured arrays in NumPy through seven illustrative examples, spanning basic to advanced usage scenarios. Structured arrays allow users to create ndarrays with compound data types. These data types can aggregate different scalar data types, permitting the storage of ...
Top answer
1 of 2
14

I'm afraid it's not possible without twisting NumPy's arm a lot.

See, the idea behind NumPy is to provide homogeneous arrays, that is, arrays of elements that all have the same type. This type can be simple (int, float...) or more complicated ([('',int),('',float),('',"|S10")]), but in any case, all the elements have the same type. That permits some very efficient memory layout.

So, inherently, a structured array requires the fields (the individual subblocks) to have the same size no matter the position. Examine the following:

>>> np.zeros(3,dtype=[('a',(int,3)),('b',(float,5))])

It defines an array with three elements; each element is composed of two sub-blocks, a and b; a is a block of three ints, b a block of five floats. But once you define the initial size of the blocks in the dtype, you're stuck with that (well, you can always switch, but that's another story).

There's a workaround: using a dtype=object. That way, you're constructing an array of heterogeneous items, like an array of lists of different sizes. But you lose a lot of NumPy power that way. Still, an example:

>>> x=np.zeros(3, dtype=[('a',object), ('b',object)])
>>> x['a'][0] = [1,2,3,4]
>>> x['b'][-1] = "ABCDEF"
>>> print x
[([1, 2, 3, 4], 0) (0, 0) (0, 'ABCD')]

So, we just constructed an array of... objects. I put a list somewhere, a string elsewhere, and it works. You could follow the same example to build an array like you want:

blob = np.array([(a,b,c)],dtype=[('a',object),('b',object),('c',object)])

but then, you should really think twice whether it's really a mean to your end, another structure would probably be more efficient.

A side note: please pay attention to the [(a,b,c)] part of the expression above: notice the ()? You're basically telling NumPy to construct an array of 1 element, composed of three sub-elements (one for each of your a,b,c), each sub-element being an object. If you don't put the (), NumPy will whine a lot.

And a last comment: if you access your fields like blob['a'], you'll get an array of size (1,) and dtype=object: just use blob['a'].item() to get back your original (6,) int array.

2 of 2
7

In python a dictionary is roughly analogs to a structure in Matlab. You could try the following to see if it works for you:

>>> data = {'a':a, 'b':b, 'c':c}
>>> data['a'] is a
True