Q:

Write a NumPy program to create a record array from a (flat) list of arrays

0

Write a NumPy program to create a record array from a (flat) list of arrays.
Sample arrays: [1,2,3,4], ['Red', 'Green', 'White', 'Orange'], [12.20,15,20,40]

All Answers

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

import numpy as np
a1=np.array([1,2,3,4])
a2=np.array(['Red','Green','White','Orange'])
a3=np.array([12.20,15,20,40])
result= np.core.records.fromarrays([a1, a2, a3],names='a,b,c')
print(result[0])
print(result[1])
print(result[2])

 

Sample Output:
(1, 'Red', 12.2)                                                       
(2, 'Green', 15.0)                                                     
(3, 'White', 20.0)

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