Python | Numpy’s fromrecords () method

Using the numpy.core.fromrecords() method we can create an array of records using a list of individual records using numpy.core.fromrecords () .

Syntax: numpy.core.fromrecords ([(tup1), (tup2)], metadata)

Return: Return the record of an array.

Example # 1:

In this example, we can see that using numpy.core.fromrecords () , we can get an array of records using individual list entries.

# NumPy import

import numpy as np

 
# using the numpy.core.fromrecords () method

gfg = < code class = "plain"> np.core.records.fromrecords ([( 101 , 'Jitender' , 21 ),

( 102 , 'Deepak' , 20 )], 

names = 'Rollno, Name, Age' )

 

print (gfg [ 0 ])

Output:

(101, 'Jitender', 21)

< strong> Example # 2:

# NumPy imports

import numpy as np

 
# using the numpy.core.fromrecords () method

gfg = np.core.records.fromrecords ([( 101 , 'Jitender' , 21 ),

( 102 , 'Deepak' , 20 )],

  names = 'Rollno, Name, Age' )

 

print (gfg.Name)

Output:

['Jitender' 'Deepak']





Get Solution for free from DataCamp guru