Open In App

Python - Numpy fromrecords() method

Last Updated : 12 Jul, 2025
Comments
Improve
Suggest changes
8 Likes
Like
Report

numpy.fromrecords() method is a powerful tool in the NumPy library that allows you to create structured arrays from a sequence of tuples or other array-like objects.

Let's understand the help of an example:

Output:

[(1, 'Alice', 25.5) (2, 'Bob', 30. ) (3, 'Charlie', 28. )]

Syntax of Numpy fromrecords():

numpy.fromrecords(recList, dtype=None, shape=None, aligned=False, byteorder=None)

Parameters:

  • recList: A list of tuples or structured data to be converted into a structured NumPy array.
  • dtype (optional): The data type of the resulting structured array. If not provided, NumPy will infer the type from the input data.
  • shape (optional): Shape of the output array. Defaults to one-dimensional.
  • aligned (optional): If True, aligns fields to their natural alignment.
  • byteorder (optional): Specifies the byte order of the output array.

Accessing Structured Array Fields

We can access specific fields (columns) in the structured array by their names.

Output:

[(1, 'Alice', 25.5) (2, 'Bob', 30. ) (3, 'Charlie', 28. )]

Article Tags :

Explore