I would like to get the attribute of every object contained in an ndarray. Consider the following code, where after vectorization the function returns an ndarray with the objects. From each of these objects in the array, I would like to get the attribute and store the attributes in a new array.
The classes and functions are a dummy for more complex classes and functions. I am aware of the fact that from stud = new_student(["Michael","Rachel"], [1,2]); stud.name
I could get a list with the names, however this is not possible with the function I am using instead of new_student
.
import numpy as np
class Student:
# class variable
stream = "COE"
# Constructor
def __init__(self, name, roll_no):
self.name = name
self.roll_no = roll_no
def new_student(name, roll_no):
return Student(name, roll_no)
new_student_vec = np.vectorize(new_student)
studArr = new_student_vec(["Michael","Rachel"], [1,2])
studArr.name