def histogram(data, nbins, range=None): """ Comes from Konrad Hinsen: Scientific Python """ data = Numeric.array(data, Numeric.Float) if range is None: min = Numeric.minimum.reduce(data) max = Numeric.maximum.reduce(data) else: min, max = range data = Numeric.repeat( data, Numeric.logical_and(Numeric.less_equal(data, max), Numeric.greater_equal(data, min))) # end if bin_width = (max - min) / nbins data = Numeric.floor((data - min) / bin_width).astype(Numeric.Int) histo = Numeric.add.reduce( Numeric.equal(Numeric.arange(nbins)[:, Numeric.NewAxis], data), -1) histo[-1] = histo[-1] + Numeric.add.reduce(Numeric.equal(nbins, data)) bins = min + bin_width * (Numeric.arange(nbins) + 0.5) return Numeric.transpose(Numeric.array([bins, histo]))
def histogram(data, nbins, range = None): """ Comes from Konrad Hinsen: Scientific Python """ data = Numeric.array(data, Numeric.Float) if range is None: min = Numeric.minimum.reduce(data) max = Numeric.maximum.reduce(data) else: min, max = range data = Numeric.repeat(data, Numeric.logical_and(Numeric.less_equal(data, max), Numeric.greater_equal(data, min))) # end if bin_width = (max-min)/nbins data = Numeric.floor((data - min)/bin_width).astype(Numeric.Int) histo = Numeric.add.reduce(Numeric.equal( Numeric.arange(nbins)[:,Numeric.NewAxis], data), -1) histo[-1] = histo[-1] + Numeric.add.reduce(Numeric.equal(nbins, data)) bins = min + bin_width*(Numeric.arange(nbins)+0.5) return Numeric.transpose(Numeric.array([bins, histo]))
def histogram(data, nbins, range = None): """ Create a histogram. Comes from Konrad Hinsen: Scientific Python @param data: data list or array @type data: [any] @param nbins: number of bins @type nbins: int @param range: data range to create histogram from (min val, max val) @type range: (float, float) OR None @return: array (2 x len(data) ) with start of bin and witdh of bin. @rtype: array """ data = Numeric.array(data, Numeric.Float) if range is None: min = Numeric.minimum.reduce(data) max = Numeric.maximum.reduce(data) else: min, max = range data = Numeric.repeat(data, Numeric.logical_and(Numeric.less_equal(data, max), Numeric.greater_equal(data, min))) bin_width = (max-min)/nbins data = Numeric.floor((data - min)/bin_width).astype(Numeric.Int) histo = Numeric.add.reduce(Numeric.equal( Numeric.arange(nbins)[:,Numeric.NewAxis], data), -1) histo[-1] = histo[-1] + Numeric.add.reduce(Numeric.equal(nbins, data)) bins = min + bin_width*(Numeric.arange(nbins)+0.5) return Numeric.transpose(Numeric.array([bins, histo]))
def extractU(self, v): "Extract curve in u-direction at parameter v." if numerix.any(v < 0.) or numerix.any(v > 1.): raise NURBSError, 'Out of parameter range [0,1]' if v == 0.: cntrl = self.cntrl[:, :, 0] knots = self.uknots[:] elif v == 1.: cntrl = self.cntrl[:, :, -1] knots = self.uknots[:] else: vknots = numerix.repeat( numerix.asarray([v], numerix.Float), [self.degree[0] * (self.cntrl.shape[1] + 1)]) coefs = numerix.resize( self.cntrl, (4 * self.cntrl.shape[1], self.cntrl.shape[2])) coefs, knots = bspkntins(self.degree[1], coefs, self.vknots, vknots) cntrl = numerix.resize(coefs, (4, self.cntrl.shape[1], coefs.shape[1])) i = 0 j = knots[0] for k in knots[1:]: if k == v: break elif k != j: i += 1 j = k return Crv.Crv(cntrl[:, :, i], self.uknots[:])
def extractV(self, u): "Extract curve in v-direction at parameter u." if numerix.any(u < 0.) or numerix.any(u > 1.): raise NURBSError, 'Out of parameter range [0,1]' if u == 0.: cntrl = self.cntrl[:, 0, :] knots = self.vknots[:] elif u == 1.: cntrl = self.cntrl[:, -1, :] knots = self.vknots[:] else: uknots = numerix.repeat( numerix.asarray([u], numerix.Float), [self.degree[1] * (self.cntrl.shape[2] + 1)]) coefs = numerix.transpose(self.cntrl, (0, 2, 1)) coefs = numerix.resize( coefs, (4 * self.cntrl.shape[2], self.cntrl.shape[1])) coefs, knots = bspkntins(self.degree[0], coefs, self.uknots, uknots) coefs = numerix.resize(coefs, (4, self.cntrl.shape[2], coefs.shape[1])) cntrl = numerix.transpose(coefs, (0, 2, 1)) i = 0 j = knots[0] for k in knots[1:]: if k == u: break elif k != j: i += 1 j = k return Crv.Crv(cntrl[:, i, :], self.vknots[:])
def extractV(self, u): "Extract curve in v-direction at parameter u." if numerix.any(u < 0.) or numerix.any(u > 1.): raise NURBSError, 'Out of parameter range [0,1]' if u == 0.: cntrl = self.cntrl[:,0,:] knots = self.vknots[:] elif u == 1.: cntrl = self.cntrl[:,-1,:] knots = self.vknots[:] else: uknots = numerix.repeat(numerix.asarray([u], numerix.Float),[self.degree[1]*(self.cntrl.shape[2] + 1)]) coefs = numerix.transpose(self.cntrl,(0, 2, 1)) coefs = numerix.resize(coefs,(4*self.cntrl.shape[2], self.cntrl.shape[1])) coefs, knots = bspkntins(self.degree[0], coefs, self.uknots, uknots) coefs = numerix.resize(coefs, (4, self.cntrl.shape[2], coefs.shape[1])) cntrl = numerix.transpose(coefs,(0,2,1)) i = 0 j = knots[0] for k in knots[1:]: if k == u: break elif k != j: i += 1 j = k return Crv.Crv(cntrl[:,i,:], self.vknots[:])
def histogram(data, nbins, range=None): """ Create a histogram. Comes from Konrad Hinsen: Scientific Python @param data: data list or array @type data: [any] @param nbins: number of bins @type nbins: int @param range: data range to create histogram from (min val, max val) @type range: (float, float) OR None @return: array (2 x len(data) ) with start of bin and witdh of bin. @rtype: array """ data = Numeric.array(data, Numeric.Float) if range is None: min = Numeric.minimum.reduce(data) max = Numeric.maximum.reduce(data) else: min, max = range data = Numeric.repeat( data, Numeric.logical_and(Numeric.less_equal(data, max), Numeric.greater_equal(data, min))) bin_width = (max - min) / nbins data = Numeric.floor((data - min) / bin_width).astype(Numeric.Int) histo = Numeric.add.reduce( Numeric.equal(Numeric.arange(nbins)[:, Numeric.NewAxis], data), -1) histo[-1] = histo[-1] + Numeric.add.reduce(Numeric.equal(nbins, data)) bins = min + bin_width * (Numeric.arange(nbins) + 0.5) return Numeric.transpose(Numeric.array([bins, histo]))
def extractU(self, v): "Extract curve in u-direction at parameter v." if numerix.any(v < 0.) or numerix.any(v > 1.): raise NURBSError, 'Out of parameter range [0,1]' if v == 0.: cntrl = self.cntrl[:,:,0] knots = self.uknots[:] elif v == 1.: cntrl = self.cntrl[:,:,-1] knots = self.uknots[:] else: vknots = numerix.repeat(numerix.asarray([v], numerix.Float),[self.degree[0]*(self.cntrl.shape[1] + 1)]) coefs = numerix.resize(self.cntrl,(4*self.cntrl.shape[1], self.cntrl.shape[2])) coefs, knots = bspkntins(self.degree[1], coefs, self.vknots, vknots) cntrl = numerix.resize(coefs, (4, self.cntrl.shape[1], coefs.shape[1])) i = 0 j = knots[0] for k in knots[1:]: if k == v: break elif k != j: i += 1 j = k return Crv.Crv(cntrl[:,:,i], self.uknots[:])