Python numpy.ma() Examples
The following are 30
code examples of numpy.ma().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example #1
Source File: bench.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def timer(s, v='', nloop=500, nrep=3): units = ["s", "ms", "µs", "ns"] scaling = [1, 1e3, 1e6, 1e9] print("%s : %-50s : " % (v, s), end=' ') varnames = ["%ss,nm%ss,%sl,nm%sl" % tuple(x*4) for x in 'xyz'] setup = 'from __main__ import numpy, ma, %s' % ','.join(varnames) Timer = timeit.Timer(stmt=s, setup=setup) best = min(Timer.repeat(nrep, nloop)) / nloop if best > 0.0: order = min(-int(numpy.floor(numpy.log10(best)) // 3), 3) else: order = 3 print("%d loops, best of %d: %.*g %s per loop" % (nloop, nrep, 3, best * scaling[order], units[order]))
Example #2
Source File: bench.py From mxnet-lambda with Apache License 2.0 | 6 votes |
def timer(s, v='', nloop=500, nrep=3): units = ["s", "ms", "µs", "ns"] scaling = [1, 1e3, 1e6, 1e9] print("%s : %-50s : " % (v, s), end=' ') varnames = ["%ss,nm%ss,%sl,nm%sl" % tuple(x*4) for x in 'xyz'] setup = 'from __main__ import numpy, ma, %s' % ','.join(varnames) Timer = timeit.Timer(stmt=s, setup=setup) best = min(Timer.repeat(nrep, nloop)) / nloop if best > 0.0: order = min(-int(numpy.floor(numpy.log10(best)) // 3), 3) else: order = 3 print("%d loops, best of %d: %.*g %s per loop" % (nloop, nrep, 3, best * scaling[order], units[order]))
Example #3
Source File: bench.py From lambda-packs with MIT License | 6 votes |
def timer(s, v='', nloop=500, nrep=3): units = ["s", "ms", "µs", "ns"] scaling = [1, 1e3, 1e6, 1e9] print("%s : %-50s : " % (v, s), end=' ') varnames = ["%ss,nm%ss,%sl,nm%sl" % tuple(x*4) for x in 'xyz'] setup = 'from __main__ import numpy, ma, %s' % ','.join(varnames) Timer = timeit.Timer(stmt=s, setup=setup) best = min(Timer.repeat(nrep, nloop)) / nloop if best > 0.0: order = min(-int(numpy.floor(numpy.log10(best)) // 3), 3) else: order = 3 print("%d loops, best of %d: %.*g %s per loop" % (nloop, nrep, 3, best * scaling[order], units[order]))
Example #4
Source File: test_old_ma.py From mxnet-lambda with Apache License 2.0 | 6 votes |
def test_testPut(self): # Test of put with suppress_warnings() as sup: sup.filter( np.ma.core.MaskedArrayFutureWarning, "setting an item on a masked array which has a " "shared mask will not copy") d = arange(5) n = [0, 0, 0, 1, 1] m = make_mask(n) x = array(d, mask=m) self.assertTrue(x[3] is masked) self.assertTrue(x[4] is masked) x[[1, 4]] = [10, 40] self.assertTrue(x.mask is not m) self.assertTrue(x[3] is masked) self.assertTrue(x[4] is not masked) self.assertTrue(eq(x, [0, 10, 2, -1, 40])) x = array(d, mask=m) x.put([0, 1, 2], [-1, 100, 200]) self.assertTrue(eq(x, [-1, 100, 200, 0, 0])) self.assertTrue(x[3] is masked) self.assertTrue(x[4] is masked)
Example #5
Source File: bench.py From recruit with Apache License 2.0 | 6 votes |
def timer(s, v='', nloop=500, nrep=3): units = ["s", "ms", "µs", "ns"] scaling = [1, 1e3, 1e6, 1e9] print("%s : %-50s : " % (v, s), end=' ') varnames = ["%ss,nm%ss,%sl,nm%sl" % tuple(x*4) for x in 'xyz'] setup = 'from __main__ import numpy, ma, %s' % ','.join(varnames) Timer = timeit.Timer(stmt=s, setup=setup) best = min(Timer.repeat(nrep, nloop)) / nloop if best > 0.0: order = min(-int(numpy.floor(numpy.log10(best)) // 3), 3) else: order = 3 print("%d loops, best of %d: %.*g %s per loop" % (nloop, nrep, 3, best * scaling[order], units[order]))
Example #6
Source File: bench.py From pySINDy with MIT License | 6 votes |
def timer(s, v='', nloop=500, nrep=3): units = ["s", "ms", "µs", "ns"] scaling = [1, 1e3, 1e6, 1e9] print("%s : %-50s : " % (v, s), end=' ') varnames = ["%ss,nm%ss,%sl,nm%sl" % tuple(x*4) for x in 'xyz'] setup = 'from __main__ import numpy, ma, %s' % ','.join(varnames) Timer = timeit.Timer(stmt=s, setup=setup) best = min(Timer.repeat(nrep, nloop)) / nloop if best > 0.0: order = min(-int(numpy.floor(numpy.log10(best)) // 3), 3) else: order = 3 print("%d loops, best of %d: %.*g %s per loop" % (nloop, nrep, 3, best * scaling[order], units[order]))
Example #7
Source File: test_old_ma.py From lambda-packs with MIT License | 6 votes |
def test_testPut(self): # Test of put with suppress_warnings() as sup: sup.filter( np.ma.core.MaskedArrayFutureWarning, "setting an item on a masked array which has a " "shared mask will not copy") d = arange(5) n = [0, 0, 0, 1, 1] m = make_mask(n) x = array(d, mask=m) self.assertTrue(x[3] is masked) self.assertTrue(x[4] is masked) x[[1, 4]] = [10, 40] self.assertTrue(x.mask is not m) self.assertTrue(x[3] is masked) self.assertTrue(x[4] is not masked) self.assertTrue(eq(x, [0, 10, 2, -1, 40])) x = array(d, mask=m) x.put([0, 1, 2], [-1, 100, 200]) self.assertTrue(eq(x, [-1, 100, 200, 0, 0])) self.assertTrue(x[3] is masked) self.assertTrue(x[4] is masked)
Example #8
Source File: _functions.py From pseudonetcdf with GNU Lesser General Public License v3.0 | 6 votes |
def mask_vals(f, maskdef, metakeys=_metakeys): mtype = maskdef.split(',')[0] mval = ','.join(maskdef.split(',')[1:]) if mtype == 'where': maskexpr = 'np.ma.masked_where(mask, var[:].view(np.ndarray))' # mask = eval(mval, None, f.variables) else: maskexpr = 'np.ma.masked_%s(var[:], %s)' % (mtype, mval) for varkey, var in f.variables.items(): if varkey not in metakeys: try: vout = eval(maskexpr) f.variables[varkey] = PseudoNetCDFMaskedVariable( f, varkey, var.dtype.char, var.dimensions, values=vout, **dict([(pk, getattr(var, pk)) for pk in var.ncattrs()])) except Exception as e: warn('Cannot mask %s: %s' % (varkey, str(e))) return f
Example #9
Source File: bench.py From lambda-packs with MIT License | 6 votes |
def timer(s, v='', nloop=500, nrep=3): units = ["s", "ms", "µs", "ns"] scaling = [1, 1e3, 1e6, 1e9] print("%s : %-50s : " % (v, s), end=' ') varnames = ["%ss,nm%ss,%sl,nm%sl" % tuple(x*4) for x in 'xyz'] setup = 'from __main__ import numpy, ma, %s' % ','.join(varnames) Timer = timeit.Timer(stmt=s, setup=setup) best = min(Timer.repeat(nrep, nloop)) / nloop if best > 0.0: order = min(-int(numpy.floor(numpy.log10(best)) // 3), 3) else: order = 3 print("%d loops, best of %d: %.*g %s per loop" % (nloop, nrep, 3, best * scaling[order], units[order]))
Example #10
Source File: bench.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def compare_functions_2v(func, nloop=500, test=True, xs=xs, nmxs=nmxs, ys=ys, nmys=nmys, xl=xl, nmxl=nmxl, yl=yl, nmyl=nmyl): funcname = func.__name__ print("-"*50) print("%s on small arrays" % funcname) module, data = "numpy.ma", "nmxs,nmys" timer("%(module)s.%(funcname)s(%(data)s)" % locals(), v="%11s" % module, nloop=nloop) # print("%s on large arrays" % funcname) module, data = "numpy.ma", "nmxl,nmyl" timer("%(module)s.%(funcname)s(%(data)s)" % locals(), v="%11s" % module, nloop=nloop) return ############################################################################### ################################################################################
Example #11
Source File: bench.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def timer(s, v='', nloop=500, nrep=3): units = ["s", "ms", "µs", "ns"] scaling = [1, 1e3, 1e6, 1e9] print("%s : %-50s : " % (v, s), end=' ') varnames = ["%ss,nm%ss,%sl,nm%sl" % tuple(x*4) for x in 'xyz'] setup = 'from __main__ import numpy, ma, %s' % ','.join(varnames) Timer = timeit.Timer(stmt=s, setup=setup) best = min(Timer.repeat(nrep, nloop)) / nloop if best > 0.0: order = min(-int(numpy.floor(numpy.log10(best)) // 3), 3) else: order = 3 print("%d loops, best of %d: %.*g %s per loop" % (nloop, nrep, 3, best * scaling[order], units[order])) # ip.magic('timeit -n%i %s' % (nloop,s))
Example #12
Source File: bench.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def timer(s, v='', nloop=500, nrep=3): units = ["s", "ms", "µs", "ns"] scaling = [1, 1e3, 1e6, 1e9] print("%s : %-50s : " % (v, s), end=' ') varnames = ["%ss,nm%ss,%sl,nm%sl" % tuple(x*4) for x in 'xyz'] setup = 'from __main__ import numpy, ma, %s' % ','.join(varnames) Timer = timeit.Timer(stmt=s, setup=setup) best = min(Timer.repeat(nrep, nloop)) / nloop if best > 0.0: order = min(-int(numpy.floor(numpy.log10(best)) // 3), 3) else: order = 3 print("%d loops, best of %d: %.*g %s per loop" % (nloop, nrep, 3, best * scaling[order], units[order]))
Example #13
Source File: bench.py From vnpy_crypto with MIT License | 6 votes |
def timer(s, v='', nloop=500, nrep=3): units = ["s", "ms", "µs", "ns"] scaling = [1, 1e3, 1e6, 1e9] print("%s : %-50s : " % (v, s), end=' ') varnames = ["%ss,nm%ss,%sl,nm%sl" % tuple(x*4) for x in 'xyz'] setup = 'from __main__ import numpy, ma, %s' % ','.join(varnames) Timer = timeit.Timer(stmt=s, setup=setup) best = min(Timer.repeat(nrep, nloop)) / nloop if best > 0.0: order = min(-int(numpy.floor(numpy.log10(best)) // 3), 3) else: order = 3 print("%d loops, best of %d: %.*g %s per loop" % (nloop, nrep, 3, best * scaling[order], units[order]))
Example #14
Source File: mlab.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
def poly_between(x, ylower, yupper): """ Given a sequence of *x*, *ylower* and *yupper*, return the polygon that fills the regions between them. *ylower* or *yupper* can be scalar or iterable. If they are iterable, they must be equal in length to *x*. Return value is *x*, *y* arrays for use with :meth:`matplotlib.axes.Axes.fill`. """ if any(isinstance(var, np.ma.MaskedArray) for var in [ylower, yupper, x]): numpy = np.ma else: numpy = np Nx = len(x) if not cbook.iterable(ylower): ylower = ylower*numpy.ones(Nx) if not cbook.iterable(yupper): yupper = yupper*numpy.ones(Nx) x = numpy.concatenate((x, x[::-1])) y = numpy.concatenate((yupper, ylower[::-1])) return x, y
Example #15
Source File: bench.py From Computable with MIT License | 6 votes |
def timer(s, v='', nloop=500, nrep=3): units = ["s", "ms", "µs", "ns"] scaling = [1, 1e3, 1e6, 1e9] print("%s : %-50s : " % (v, s), end=' ') varnames = ["%ss,nm%ss,%sl,nm%sl" % tuple(x*4) for x in 'xyz'] setup = 'from __main__ import numpy, ma, %s' % ','.join(varnames) Timer = timeit.Timer(stmt=s, setup=setup) best = min(Timer.repeat(nrep, nloop)) / nloop if best > 0.0: order = min(-int(numpy.floor(numpy.log10(best)) // 3), 3) else: order = 3 print("%d loops, best of %d: %.*g %s per loop" % (nloop, nrep, 3, best * scaling[order], units[order])) # ip.magic('timeit -n%i %s' % (nloop,s))
Example #16
Source File: mlab.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def poly_between(x, ylower, yupper): """ Given a sequence of *x*, *ylower* and *yupper*, return the polygon that fills the regions between them. *ylower* or *yupper* can be scalar or iterable. If they are iterable, they must be equal in length to *x*. Return value is *x*, *y* arrays for use with :meth:`matplotlib.axes.Axes.fill`. """ if any(isinstance(var, np.ma.MaskedArray) for var in [ylower, yupper, x]): numpy = np.ma else: numpy = np Nx = len(x) if not cbook.iterable(ylower): ylower = ylower*numpy.ones(Nx) if not cbook.iterable(yupper): yupper = yupper*numpy.ones(Nx) x = numpy.concatenate((x, x[::-1])) y = numpy.concatenate((yupper, ylower[::-1])) return x, y
Example #17
Source File: mlab.py From Computable with MIT License | 6 votes |
def poly_between(x, ylower, yupper): """ Given a sequence of *x*, *ylower* and *yupper*, return the polygon that fills the regions between them. *ylower* or *yupper* can be scalar or iterable. If they are iterable, they must be equal in length to *x*. Return value is *x*, *y* arrays for use with :meth:`matplotlib.axes.Axes.fill`. """ if ma.isMaskedArray(ylower) or ma.isMaskedArray(yupper) or ma.isMaskedArray(x): numpy = ma else: numpy = np Nx = len(x) if not cbook.iterable(ylower): ylower = ylower*numpy.ones(Nx) if not cbook.iterable(yupper): yupper = yupper*numpy.ones(Nx) x = numpy.concatenate( (x, x[::-1]) ) y = numpy.concatenate( (yupper, ylower[::-1]) ) return x,y
Example #18
Source File: bench.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def timer(s, v='', nloop=500, nrep=3): units = ["s", "ms", "µs", "ns"] scaling = [1, 1e3, 1e6, 1e9] print("%s : %-50s : " % (v, s), end=' ') varnames = ["%ss,nm%ss,%sl,nm%sl" % tuple(x*4) for x in 'xyz'] setup = 'from __main__ import numpy, ma, %s' % ','.join(varnames) Timer = timeit.Timer(stmt=s, setup=setup) best = min(Timer.repeat(nrep, nloop)) / nloop if best > 0.0: order = min(-int(numpy.floor(numpy.log10(best)) // 3), 3) else: order = 3 print("%d loops, best of %d: %.*g %s per loop" % (nloop, nrep, 3, best * scaling[order], units[order]))
Example #19
Source File: bench.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def timer(s, v='', nloop=500, nrep=3): units = ["s", "ms", "µs", "ns"] scaling = [1, 1e3, 1e6, 1e9] print("%s : %-50s : " % (v, s), end=' ') varnames = ["%ss,nm%ss,%sl,nm%sl" % tuple(x*4) for x in 'xyz'] setup = 'from __main__ import numpy, ma, %s' % ','.join(varnames) Timer = timeit.Timer(stmt=s, setup=setup) best = min(Timer.repeat(nrep, nloop)) / nloop if best > 0.0: order = min(-int(numpy.floor(numpy.log10(best)) // 3), 3) else: order = 3 print("%d loops, best of %d: %.*g %s per loop" % (nloop, nrep, 3, best * scaling[order], units[order]))
Example #20
Source File: mlab.py From neural-network-animation with MIT License | 6 votes |
def poly_between(x, ylower, yupper): """ Given a sequence of *x*, *ylower* and *yupper*, return the polygon that fills the regions between them. *ylower* or *yupper* can be scalar or iterable. If they are iterable, they must be equal in length to *x*. Return value is *x*, *y* arrays for use with :meth:`matplotlib.axes.Axes.fill`. """ if ma.isMaskedArray(ylower) or ma.isMaskedArray(yupper) or ma.isMaskedArray(x): numpy = ma else: numpy = np Nx = len(x) if not cbook.iterable(ylower): ylower = ylower*numpy.ones(Nx) if not cbook.iterable(yupper): yupper = yupper*numpy.ones(Nx) x = numpy.concatenate( (x, x[::-1]) ) y = numpy.concatenate( (yupper, ylower[::-1]) ) return x,y
Example #21
Source File: mlab.py From matplotlib-4-abaqus with MIT License | 6 votes |
def poly_between(x, ylower, yupper): """ Given a sequence of *x*, *ylower* and *yupper*, return the polygon that fills the regions between them. *ylower* or *yupper* can be scalar or iterable. If they are iterable, they must be equal in length to *x*. Return value is *x*, *y* arrays for use with :meth:`matplotlib.axes.Axes.fill`. """ if ma.isMaskedArray(ylower) or ma.isMaskedArray(yupper) or ma.isMaskedArray(x): numpy = ma else: numpy = np Nx = len(x) if not cbook.iterable(ylower): ylower = ylower*numpy.ones(Nx) if not cbook.iterable(yupper): yupper = yupper*numpy.ones(Nx) x = numpy.concatenate( (x, x[::-1]) ) y = numpy.concatenate( (yupper, ylower[::-1]) ) return x,y
Example #22
Source File: bench.py From mxnet-lambda with Apache License 2.0 | 5 votes |
def compare_methods(methodname, args, vars='x', nloop=500, test=True, xs=xs, nmxs=nmxs, xl=xl, nmxl=nmxl): print("-"*50) print("%s on small arrays" % methodname) data, ver = "nm%ss" % vars, 'numpy.ma' timer("%(data)s.%(methodname)s(%(args)s)" % locals(), v=ver, nloop=nloop) print("%s on large arrays" % methodname) data, ver = "nm%sl" % vars, 'numpy.ma' timer("%(data)s.%(methodname)s(%(args)s)" % locals(), v=ver, nloop=nloop) return
Example #23
Source File: bench.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def compare_methods(methodname, args, vars='x', nloop=500, test=True, xs=xs, nmxs=nmxs, xl=xl, nmxl=nmxl): print("-"*50) print("%s on small arrays" % methodname) data, ver = "nm%ss" % vars, 'numpy.ma' timer("%(data)s.%(methodname)s(%(args)s)" % locals(), v=ver, nloop=nloop) print("%s on large arrays" % methodname) data, ver = "nm%sl" % vars, 'numpy.ma' timer("%(data)s.%(methodname)s(%(args)s)" % locals(), v=ver, nloop=nloop) return
Example #24
Source File: test_old_ma.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_testUfuncRegression(self): f_invalid_ignore = [ 'sqrt', 'arctanh', 'arcsin', 'arccos', 'arccosh', 'arctanh', 'log', 'log10', 'divide', 'true_divide', 'floor_divide', 'remainder', 'fmod'] for f in ['sqrt', 'log', 'log10', 'exp', 'conjugate', 'sin', 'cos', 'tan', 'arcsin', 'arccos', 'arctan', 'sinh', 'cosh', 'tanh', 'arcsinh', 'arccosh', 'arctanh', 'absolute', 'fabs', 'negative', 'floor', 'ceil', 'logical_not', 'add', 'subtract', 'multiply', 'divide', 'true_divide', 'floor_divide', 'remainder', 'fmod', 'hypot', 'arctan2', 'equal', 'not_equal', 'less_equal', 'greater_equal', 'less', 'greater', 'logical_and', 'logical_or', 'logical_xor']: try: uf = getattr(umath, f) except AttributeError: uf = getattr(fromnumeric, f) mf = getattr(np.ma, f) args = self.d[:uf.nin] with np.errstate(): if f in f_invalid_ignore: np.seterr(invalid='ignore') if f in ['arctanh', 'log', 'log10']: np.seterr(divide='ignore') ur = uf(*args) mr = mf(*args) assert_(eq(ur.filled(0), mr.filled(0), f)) assert_(eqmask(ur.mask, mr.mask))
Example #25
Source File: test_old_ma.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_testMixedArithmetic(self): na = np.array([1]) ma = array([1]) assert_(isinstance(na + ma, MaskedArray)) assert_(isinstance(ma + na, MaskedArray))
Example #26
Source File: bench.py From mxnet-lambda with Apache License 2.0 | 5 votes |
def compare_functions_2v(func, nloop=500, test=True, xs=xs, nmxs=nmxs, ys=ys, nmys=nmys, xl=xl, nmxl=nmxl, yl=yl, nmyl=nmyl): funcname = func.__name__ print("-"*50) print("%s on small arrays" % funcname) module, data = "numpy.ma", "nmxs,nmys" timer("%(module)s.%(funcname)s(%(data)s)" % locals(), v="%11s" % module, nloop=nloop) print("%s on large arrays" % funcname) module, data = "numpy.ma", "nmxl,nmyl" timer("%(module)s.%(funcname)s(%(data)s)" % locals(), v="%11s" % module, nloop=nloop) return
Example #27
Source File: mlab.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def poly_below(xmin, xs, ys): """ Given a sequence of *xs* and *ys*, return the vertices of a polygon that has a horizontal base at *xmin* and an upper bound at the *ys*. *xmin* is a scalar. Intended for use with :meth:`matplotlib.axes.Axes.fill`, e.g.,:: xv, yv = poly_below(0, x, y) ax.fill(xv, yv) """ if any(isinstance(var, np.ma.MaskedArray) for var in [xs, ys]): numpy = np.ma else: numpy = np xs = numpy.asarray(xs) ys = numpy.asarray(ys) Nx = len(xs) Ny = len(ys) if Nx != Ny: raise ValueError("'xs' and 'ys' must have the same length") x = xmin*numpy.ones(2*Nx) y = numpy.ones(2*Nx) x[:Nx] = xs y[:Nx] = ys y[Nx:] = ys[::-1] return x, y
Example #28
Source File: test_old_ma.py From mxnet-lambda with Apache License 2.0 | 5 votes |
def test_testUfuncRegression(self): f_invalid_ignore = [ 'sqrt', 'arctanh', 'arcsin', 'arccos', 'arccosh', 'arctanh', 'log', 'log10', 'divide', 'true_divide', 'floor_divide', 'remainder', 'fmod'] for f in ['sqrt', 'log', 'log10', 'exp', 'conjugate', 'sin', 'cos', 'tan', 'arcsin', 'arccos', 'arctan', 'sinh', 'cosh', 'tanh', 'arcsinh', 'arccosh', 'arctanh', 'absolute', 'fabs', 'negative', 'floor', 'ceil', 'logical_not', 'add', 'subtract', 'multiply', 'divide', 'true_divide', 'floor_divide', 'remainder', 'fmod', 'hypot', 'arctan2', 'equal', 'not_equal', 'less_equal', 'greater_equal', 'less', 'greater', 'logical_and', 'logical_or', 'logical_xor']: try: uf = getattr(umath, f) except AttributeError: uf = getattr(fromnumeric, f) mf = getattr(np.ma, f) args = self.d[:uf.nin] with np.errstate(): if f in f_invalid_ignore: np.seterr(invalid='ignore') if f in ['arctanh', 'log', 'log10']: np.seterr(divide='ignore') ur = uf(*args) mr = mf(*args) self.assertTrue(eq(ur.filled(0), mr.filled(0), f)) self.assertTrue(eqmask(ur.mask, mr.mask))
Example #29
Source File: bench.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def compare_functions_1v(func, nloop=500, xs=xs, nmxs=nmxs, xl=xl, nmxl=nmxl): funcname = func.__name__ print("-"*50) print("%s on small arrays" % funcname) module, data = "numpy.ma", "nmxs" timer("%(module)s.%(funcname)s(%(data)s)" % locals(), v="%11s" % module, nloop=nloop) print("%s on large arrays" % funcname) module, data = "numpy.ma", "nmxl" timer("%(module)s.%(funcname)s(%(data)s)" % locals(), v="%11s" % module, nloop=nloop) return
Example #30
Source File: mlab.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def poly_below(xmin, xs, ys): """ Given a sequence of *xs* and *ys*, return the vertices of a polygon that has a horizontal base at *xmin* and an upper bound at the *ys*. *xmin* is a scalar. Intended for use with :meth:`matplotlib.axes.Axes.fill`, e.g.,:: xv, yv = poly_below(0, x, y) ax.fill(xv, yv) """ if any(isinstance(var, np.ma.MaskedArray) for var in [xs, ys]): numpy = np.ma else: numpy = np xs = numpy.asarray(xs) ys = numpy.asarray(ys) Nx = len(xs) Ny = len(ys) if Nx != Ny: raise ValueError("'xs' and 'ys' must have the same length") x = xmin*numpy.ones(2*Nx) y = numpy.ones(2*Nx) x[:Nx] = xs y[:Nx] = ys y[Nx:] = ys[::-1] return x, y