Subclassing Numpy Array - Propagate Attributes : <p>I would like to know how custom attributes of numpy arrays can be propagated, even when the array passes through functions like <code>np.fromfunction</code>. </p>

<p>For example, my class <code>ExampleTensor</code> defines an attribute <code>attr</code> that is set to 1 on default.</p>

<pre><code>import numpy as np

class ExampleTensor(np.ndarray):
    def __new__(cls, input_array):
        return np.asarray(input_array).view(cls)

    def __array_finalize__(self, obj) -&gt; None:
        if obj is None: return
        # This attribute should be maintained!
        self.attr = getattr(obj, 'attr', 1)
</code></pre>

<p>Slicing and basic operations between <code>ExampleTensor</code> instances will maintain the attributes, but using other numpy functions will not (probably because they create regular numpy arrays instead of ExampleTensors). <strong>My question:</strong> Is there a solution that persists the custom attributes when a regular numpy array is constructed out of subclassed 
numpy array instances?</p>

<p>Example to reproduce problem:</p>

<pre><code>ex1 = ExampleTensor([[3, 4],[5, 6]])
ex1.attr = "some val"

print(ex1[0].attr)    # correctly outputs "some val"
print((ex1+ex1).attr) # correctly outputs "some val"

np.sum([ex1, ex1], axis=0).attr # Attribute Error: 'numpy.ndarray' object has no attribute 'attr'
</code></pre>
