本文整理汇总了Python中numerix.take函数的典型用法代码示例。如果您正苦于以下问题:Python take函数的具体用法?Python take怎么用?Python take使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了take函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
def __call__(self):
'Return the locations of the ticks'
self.verify_intervals()
b=self._base
vmin, vmax = self.viewInterval.get_bounds()
vmin = math.log(vmin)/math.log(b)
vmax = math.log(vmax)/math.log(b)
if vmax<vmin:
vmin, vmax = vmax, vmin
ticklocs = []
numdec = math.floor(vmax)-math.ceil(vmin)
if self._subs is None: # autosub
if numdec>10: subs = array([1.0])
elif numdec>6: subs = arange(2.0, b, 2.0)
else: subs = arange(2.0, b)
else:
subs = self._subs
for decadeStart in b**arange(math.floor(vmin),math.ceil(vmax)):
ticklocs.extend( subs*decadeStart )
if(len(subs) and subs[0]==1.0):
ticklocs.append(b**math.ceil(vmax))
ticklocs = array(ticklocs)
ind = nonzero(logical_and(ticklocs>=b**vmin ,
ticklocs<=b**vmax))
ticklocs = take(ticklocs,ind)
return ticklocs
示例2: makeMappingArray
def makeMappingArray(N, data):
"""Create an N-element 1-d lookup table
data represented by a list of x,y0,y1 mapping correspondences.
Each element in this list represents how a value between 0 and 1
(inclusive) represented by x is mapped to a corresponding value
between 0 and 1 (inclusive). The two values of y are to allow
for discontinuous mapping functions (say as might be found in a
sawtooth) where y0 represents the value of y for values of x
<= to that given, and y1 is the value to be used for x > than
that given). The list must start with x=0, end with x=1, and
all values of x must be in increasing order. Values between
the given mapping points are determined by simple linear interpolation.
The function returns an array "result" where result[x*(N-1)]
gives the closest value for values of x between 0 and 1.
"""
try:
adata = array(data)
except:
raise TypeError("data must be convertable to an array")
shape = adata.shape
if len(shape) != 2 and shape[1] != 3:
raise ValueError("data must be nx3 format")
x = adata[:,0]
y0 = adata[:,1]
y1 = adata[:,2]
if x[0] != 0. or x[-1] != 1.0:
raise ValueError(
"data mapping points must start with x=0. and end with x=1")
if sometrue(sort(x)-x):
raise ValueError(
"data mapping points must have x in increasing order")
# begin generation of lookup table
x = x * (N-1)
lut = zeros((N,), Float)
xind = arange(float(N))
ind = searchsorted(x, xind)[1:-1]
lut[1:-1] = ( divide(xind[1:-1] - take(x,ind-1),
take(x,ind)-take(x,ind-1) )
*(take(y0,ind)-take(y1,ind-1)) + take(y1,ind-1))
lut[0] = y1[0]
lut[-1] = y0[-1]
# ensure that the lut is confined to values between 0 and 1 by clipping it
clip(lut, 0.0, 1.0)
#lut = where(lut > 1., 1., lut)
#lut = where(lut < 0., 0., lut)
return lut
示例3: __call__
def __call__(self, X, alpha=1.0):
"""
X is either a scalar or an array (of any dimension).
If scalar, a tuple of rgba values is returned, otherwise
an array with the new shape = oldshape+(4,). If the X-values
are integers, then they are used as indices into the array.
If they are floating point, then they must be in the
interval (0.0, 1.0).
Alpha must be a scalar.
"""
if not self._isinit: self._init()
alpha = min(alpha, 1.0) # alpha must be between 0 and 1
alpha = max(alpha, 0.0)
self._lut[:-3, -1] = alpha
mask_bad = None
if not iterable(X):
vtype = 'scalar'
xa = array([X])
else:
vtype = 'array'
xma = ma.asarray(X)
xa = xma.filled(0)
mask_bad = ma.getmask(xma)
if typecode(xa) in typecodes['Float']:
putmask(xa, xa==1.0, 0.9999999) #Treat 1.0 as slightly less than 1.
xa = (xa * self.N).astype(Int)
# Set the over-range indices before the under-range;
# otherwise the under-range values get converted to over-range.
putmask(xa, xa>self.N-1, self._i_over)
putmask(xa, xa<0, self._i_under)
if mask_bad is not None and mask_bad.shape == xa.shape:
putmask(xa, mask_bad, self._i_bad)
rgba = take(self._lut, xa)
if vtype == 'scalar':
rgba = tuple(rgba[0,:])
return rgba