def __setitem__(self, i, value): if isinstance(i, (int, long)): self.array.set(i, value) elif isinstance(i, slice): if isinstance(value, ObjectArray): raise Exception elif isinstance(value, ndarray): what = value.array else: what = value try: Numpy.setslice(what, self.array, i.start or 0, i.stop or len(self), i.step or 1) except java.lang.IllegalArgumentException: raise ValueError("Could not broadcast arrays of different shapes") elif isinstance(i, ndarray): if isinstance(value, ObjectArray): raise Exception elif isinstance(value, ndarray): what = value.array else: what = value try: Numpy.setfancy(what, self.array, i.array) except java.lang.IllegalArgumentException: raise ValueError("Could not broadcast arrays of different shapes") except java.lang.IndexOutOfBoundsException: raise IndexError("Index out of bounds") else: raise NotImplementedError
def ones(shape, dtype=float, order="C"): if isinstance(shape, int): if dtype is bool: return ndarray(Numpy.onesBoolean(shape)) elif dtype is float: return ndarray(Numpy.onesDouble(shape)) elif dtype is int: return ndarray(Numpy.onesInteger(shape)) elif dtype is object: return ObjectArray([1] * shape) else: raise NotImplementedError else: raise NotImplementedError
def __getitem__(self, i): if isinstance(i, (int, long)): return self.array.get(i) elif isinstance(i, slice): return ndarray(Numpy.getslice(self.array, i.start or 0, i.stop or len(self), i.step or 1)) elif isinstance(i, ndarray): try: return ndarray(Numpy.getfancy(self.array, i.array)); except java.lang.IndexOutOfBoundsException: raise IndexError("Index out of bounds") else: raise NotImplementedError
def __getitem__(self, i): if isinstance(i, (int, long)): return self.array.get(i) elif isinstance(i, slice): return ndarray( Numpy.getslice(self.array, i.start or 0, i.stop or len(self), i.step or 1)) elif isinstance(i, ndarray): try: return ndarray(Numpy.getfancy(self.array, i.array)) except java.lang.IndexOutOfBoundsException: raise IndexError("Index out of bounds") else: raise NotImplementedError
def __setitem__(self, i, value): if isinstance(i, (int, long)): self.array.set(i, value) elif isinstance(i, slice): if isinstance(value, ObjectArray): raise Exception elif isinstance(value, ndarray): what = value.array else: what = value try: Numpy.setslice(what, self.array, i.start or 0, i.stop or len(self), i.step or 1) except java.lang.IllegalArgumentException: raise ValueError( "Could not broadcast arrays of different shapes") elif isinstance(i, ndarray): if isinstance(value, ObjectArray): raise Exception elif isinstance(value, ndarray): what = value.array else: what = value try: Numpy.setfancy(what, self.array, i.array) except java.lang.IllegalArgumentException: raise ValueError( "Could not broadcast arrays of different shapes") except java.lang.IndexOutOfBoundsException: raise IndexError("Index out of bounds") else: raise NotImplementedError
def count_nonzero(x): return Numpy.count_nonzero(x.array) def mean(x): return Numpy.mean(x.array)
def copy(x): return Numpy.copy(x.array) def count_nonzero(x): return Numpy.count_nonzero(x.array)
def __init__(self, pythonList): self.pythonList = pythonList self.indexArray = ndarray(Numpy.indexArray(len(pythonList)))
def __setitem__(self, i, value): if isinstance(i, (int, long)): self.pythonList[i] = value elif isinstance(i, slice): if isinstance(value, ndarray): p = self.pythonList if isinstance(value, ObjectArray): g = value.pythonList.__getitem__ else: g = value.array.get for index in xrange(i.start or 0, i.stop or len(self), i.step or 1): p[index] = g(index) else: p = self.pythonList for index in xrange(i.start or 0, i.stop or len(self), i.step or 1): p[index] = value elif isinstance(i, ndarray): if isinstance(i.array, ArrayBoolean1d): if len(i) != len(self): raise ValueError("Could not broadcast arrays of different shapes") if isinstance(value, ndarray): if Numpy.count_nonzero(i.array) != len(value): raise ValueError("Could not broadcast arrays of different shapes") j = 0 p = self.pythonList if isinstance(value, ObjectArray): g = value.pythonList.__getitem__ else: g = value.array.get for ii in xrange(len(self)): if i.array.get(ii): p[ii] = g(j) j += 1 else: p = self.pythonList for ii in xrange(len(self)): if i.array.get(ii): p[ii] = value elif isinstance(i.array, ArrayInteger1d): if isinstance(value, ndarray): if len(i) != len(value): raise ValueError("Could not broadcast arrays of different shapes") l = len(self) p = self.pythonList for ii in xrange(len(i)): index = i.array.get(ii) if index < 0: index = l + index p[index] = value[ii] else: l = len(self) p = self.pythonList for ii in xrange(len(i)): index = i.array.get(ii) if index < 0: index = l + index p[index] = value else: raise Exception
def count_nonzero(x): return Numpy.count_nonzero(x.array)
def sum(x): return Numpy.sum(x.array) except ImportError:
def nanmin(x): return Numpy.nanmin(x.array) def std(x, ddof=0): return Numpy.std(x.array, ddof)
def sum(x): return Numpy.sum(x.array)
def std(x, ddof=0): return Numpy.std(x.array, ddof)
def nanmin(x): return Numpy.nanmin(x.array)
def nanmax(x): return Numpy.nanmax(x.array)
def mean(x): return Numpy.mean(x.array)
def copy(self): return Numpy.copy(self.array)
def mean(x): return Numpy.mean(x.array) def nanmax(x): return Numpy.nanmax(x.array)
def nanmax(x): return Numpy.nanmax(x.array) def nanmin(x): return Numpy.nanmin(x.array)
def __setitem__(self, i, value): if isinstance(i, (int, long)): self.pythonList[i] = value elif isinstance(i, slice): if isinstance(value, ndarray): p = self.pythonList if isinstance(value, ObjectArray): g = value.pythonList.__getitem__ else: g = value.array.get for index in xrange(i.start or 0, i.stop or len(self), i.step or 1): p[index] = g(index) else: p = self.pythonList for index in xrange(i.start or 0, i.stop or len(self), i.step or 1): p[index] = value elif isinstance(i, ndarray): if isinstance(i.array, ArrayBoolean1d): if len(i) != len(self): raise ValueError( "Could not broadcast arrays of different shapes") if isinstance(value, ndarray): if Numpy.count_nonzero(i.array) != len(value): raise ValueError( "Could not broadcast arrays of different shapes" ) j = 0 p = self.pythonList if isinstance(value, ObjectArray): g = value.pythonList.__getitem__ else: g = value.array.get for ii in xrange(len(self)): if i.array.get(ii): p[ii] = g(j) j += 1 else: p = self.pythonList for ii in xrange(len(self)): if i.array.get(ii): p[ii] = value elif isinstance(i.array, ArrayInteger1d): if isinstance(value, ndarray): if len(i) != len(value): raise ValueError( "Could not broadcast arrays of different shapes" ) l = len(self) p = self.pythonList for ii in xrange(len(i)): index = i.array.get(ii) if index < 0: index = l + index p[index] = value[ii] else: l = len(self) p = self.pythonList for ii in xrange(len(i)): index = i.array.get(ii) if index < 0: index = l + index p[index] = value else: raise Exception
def std(x, ddof=0): return Numpy.std(x.array, ddof) def sum(x): return Numpy.sum(x.array)
def copy(x): return Numpy.copy(x.array)