Subclassing numpy ndarray problem

后端 未结 3 2114
清酒与你
清酒与你 2020-12-06 02:40

I would like to subclass numpy ndarray. However, I cannot change the array. Why self = ... does not change the array? Thanks.

import numpy as np         


        
3条回答
  •  孤街浪徒
    2020-12-06 02:51

    I tried to do the same, but it is really very complex to subclass ndarray.

    If you only have to add some functionality, I would suggest to create a class which stores the array as attribute.

    class Data(object):
    
        def __init__(self, array):
            self.array = array
    
        def remove_some(self, t):
            //operate on self.array
            pass
    
    d = Data(z)
    print(d.array)
    

提交回复
热议问题