I'm trying to create a class that inherits numpy.ndarray
, but I want to initialize it using a function that returns an ndarray
. Specifically I want to generate an ndarray
from a CSV file using the convenient numpy.genfromtxt()
function. For example (I'm aware that this code does not do what I want it to):
class MyClass(numpy.ndarray):
def __init__(self, other_parameter):
self = numpy.genfromtxt(filename, delimiter=',')
self.other_param = other_parameter
The point is that I want to extend ndarray
a little bit by adding other features/attributes without losing the interface to ndarray
. I know I can cobble together attributes in a class with one being the ndarray
. Is extending it possible using a constructor (within my class definition __init__()
) that isn't super().__init__()
?
I've found answers to this type of thing for several other languages, but not Python. I've wanted to use similar init functions before, and have never found how to do this.