Python
numpy

asarray, view and getattr method in numpy

class NamedArray(np.ndarray):
    def __new__(cls, array, name="no name"):
        print(array,type(array))
        a = np.asarray(array) # it does not change even if there is no
        print(a,type(a))
        obj = a.view(cls)
        print(obj,type(obj))
        obj.name = name
        return obj
    def __array_finalize__(self, obj):
        print(sys._getframe().f_code.co_name)
        print(type(self),type(obj))
        if obj is None: return
        g = getattr(obj, 'name', "no name")
        print(g)
        self.info = g
        g = getattr(obj, 'name', "no name")
        print(g)
        self.infotest = g

Z = NamedArray(np.arange(10), "range_10")
print (Z.name)
print (Z.info, Z.infotest)
[0 1 2 3 4 5 6 7 8 9] <class 'numpy.ndarray'>
[0 1 2 3 4 5 6 7 8 9] <class 'numpy.ndarray'>
__array_finalize__
<class '__main__.NamedArray'> <class 'numpy.ndarray'>
no name
no name
[0 1 2 3 4 5 6 7 8 9] <class '__main__.NamedArray'>
range_10
no name no name

Refs.