def __init__(self, data=None, shape=None): if data is None: data = [] if shape is None: shape = [] if isinstance(data, cndarray): self.data = data self.size = data.get_size() self.dims = data.get_dims() self.shape = data.get_shape() else: if isinstance(data, float): self.data = cndarray([data], []) elif isinstance(data, int): self.data = cndarray([data], []) elif isinstance(data, list): if shape is None: shape = [len(data)] self.data = cndarray(list(data), list(shape)) elif isinstance(data, tuple): if shape is None: shape = [len(data)] self.data = cndarray(list(data), list(shape)) else: raise Exception("cannot convert to ndarray") self.shape = shape self.dims = len(shape) self.size = self.data.get_size()
def __isub__(self, other): if not isinstance(other, ndarray): other = ndarray(cndarray([other], [])) return ndarray(self.data.__sub__(other.data))
def __rtruediv__(self, other): if not isinstance(other, ndarray): other = ndarray(cndarray([other], [])) return ndarray(other.data.__truediv__(self.data))