Jun-19-2020, 06:08 AM
Hello,
let me explain what I mean with this example
I looked into the __new__ help but I didn't get much out of it.
__new__(...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
Can any someone ilustrate with an example a similar behaviour. I've trying without success to mimic that playing with __new__,
but I must be doing something wrong.
let me explain what I mean with this example
array = np.array([[2, 0], [5, 9]]) print(array) # Result: [[2, 0], [5, 9]] print(type(array)) # Result: <type 'numpy.ndarray'> print(array.flatten()) # Result: [2 0 5 9]So as you can see arrat is a type 'numpy.ndarray' but us returned as a list of lists. I believe that __repr__ and __str__ only allow to change the object representation as a string. Here we get a list and what is really nice is that you can use methods like .flatten() modify it.
I looked into the __new__ help but I didn't get much out of it.
__new__(...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
Can any someone ilustrate with an example a similar behaviour. I've trying without success to mimic that playing with __new__,
but I must be doing something wrong.