Write a NumPy program to create a record array from a given regular array.
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)]
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer