cloud

Python Numpy Record Type

The record data type means heterogeneous data type. It is the same as representing a row of spreadsheet or a database. To give an example of a record data type, we will create a record for a shop inventory. The record contains the name of the item, a 50-character string, the number of items in the store represented by a 32-bit integer, and, finally, a price represented by a 32-bit float. These consecutive steps show how to create a record data type:

Python Numpy Record Creation :

>>> import numpy as np
>>> record = np.dtype([('Name', 'str_', 50),("Num_of_items",'int32'), ('Price','float32')])
>>> record
dtype([('Name', 'S50'), ('Num_of_items', '


Let see how to view Numpy Record data type.

Python Numpy Record Type view :

>>> record['Name']
dtype('S50') >>> record['Price']
dtype('float32')


Let see how to Enter data into Numpy Record data.

Python Numpy Record Type view :

>>> record_data = np.array([("Python_hacking", 20, 18.12),("Python for beginers", 10, 12.12)], dtype=record)
>>> record_data[0]
('Python_hacking', 20, 18.12000084)
>>> record_data
array([('Python_hacking', 20, 18.12000084),
('Python for beginers', 10, 12.11999989)],
dtype=[('Name', 'S50'), ('Num_of_items', '
You saw that above record_data variable return a list of tuples.






admin