Q:

Write a NumPy program to create a record array from a given regular array

0

Write a NumPy program to create a record array from a given regular array.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np
arra1 = np.array([("Yasemin Rayner", 88.5, 90),
                 ("Ayaana Mcnamara", 87, 99),
             ("Jody Preece", 85.5, 91)])
print("Original arrays:")
print(arra1)
print("\nRecord array;")
result = np.core.records.fromarrays(arra1.T,
                              names='col1, col2, col3',
                              formats = 'S80, f8, i8')
print(result)

Sample Output:

Original arrays:
[['Yasemin Rayner' '88.5' '90']
 ['Ayaana Mcnamara' '87' '99']
 ['Jody Preece' '85.5' '91']]

Record array;
[(b'Yasemin Rayner', 88.5, 90) (b'Ayaana Mcnamara', 87. , 99)
 (b'Jody Preece', 85.5, 91)]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now