• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python ma.asarray函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中numpy.ma.asarray函数的典型用法代码示例。如果您正苦于以下问题:Python asarray函数的具体用法?Python asarray怎么用?Python asarray使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了asarray函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: set_UVC

    def set_UVC(self, U, V, C=None):
        self.u = ma.asarray(U).ravel()
        self.v = ma.asarray(V).ravel()
        if C is not None:
            c = ma.asarray(C).ravel()
            x,y,u,v,c = delete_masked_points(self.x.ravel(), self.y.ravel(),
                self.u, self.v, c)
        else:
            x,y,u,v = delete_masked_points(self.x.ravel(), self.y.ravel(),
                self.u, self.v)

        magnitude = np.sqrt(u*u + v*v)
        flags, barbs, halves, empty = self._find_tails(magnitude,
            self.rounding, **self.barb_increments)

        #Get the vertices for each of the barbs

        plot_barbs = self._make_barbs(u, v, flags, barbs, halves, empty,
            self._length, self._pivot, self.sizes, self.fill_empty, self.flip)
        self.set_verts(plot_barbs)

        #Set the color array
        if C is not None:
            self.set_array(c)

        #Update the offsets in case the masked data changed
        xy = np.hstack((x[:,np.newaxis], y[:,np.newaxis]))
        self._offsets = xy
开发者ID:zoccolan,项目名称:eyetracker,代码行数:28,代码来源:quiver.py


示例2: __init__

 def __init__(self,*args,**kwargs):
     TestCase.__init__(self,*args,**kwargs)
     self.presidents = [nan, 87, 82, 75, 63, 50, 43, 32, 35, 60, 54, 55,
                        36, 39,nan,nan, 69, 57, 57, 51, 45, 37, 46, 39,
                        36, 24, 32, 23, 25, 32,nan, 32, 59, 74, 75, 60,
                        71, 61, 71, 57, 71, 68, 79, 73, 76, 71, 67, 75,
                        79, 62, 63, 57, 60, 49, 48, 52, 57, 62, 61, 66,
                        71, 62, 61, 57, 72, 83, 71, 78, 79, 71, 62, 74,
                        76, 64, 62, 57, 80, 73, 69, 69, 71, 64, 69, 62,
                        63, 46, 56, 44, 44, 52, 38, 46, 36, 49, 35, 44,
                        59, 65, 65, 56, 66, 53, 61, 52, 51, 48, 54, 49,
                        49, 61,nan,nan, 68, 44, 40, 27, 28, 25, 24, 24]
     self.mdeaths = [2134,1863,1877,1877,1492,1249,1280,1131,1209,1492,1621,
                     1846,2103,2137,2153,1833,1403,1288,1186,1133,1053,1347,
                     1545,2066,2020,2750,2283,1479,1189,1160,1113, 970, 999,
                     1208,1467,2059,2240,1634,1722,1801,1246,1162,1087,1013,
                      959,1179,1229,1655,2019,2284,1942,1423,1340,1187,1098,
                     1004, 970,1140,1110,1812,2263,1820,1846,1531,1215,1075,
                     1056, 975, 940,1081,1294,1341]
     self.fdeaths = [901, 689, 827, 677, 522, 406, 441, 393, 387, 582, 578,
                     666, 830, 752, 785, 664, 467, 438, 421, 412, 343, 440,
                     531, 771, 767,1141, 896, 532, 447, 420, 376, 330, 357,
                     445, 546, 764, 862, 660, 663, 643, 502, 392, 411, 348,
                     387, 385, 411, 638, 796, 853, 737, 546, 530, 446, 431,
                     362, 387, 430, 425, 679, 821, 785, 727, 612, 478, 429,
                     405, 379, 393, 411, 487, 574]
     self.mdeaths = ma.asarray(self.mdeaths)
     self.fdeaths = ma.asarray(self.fdeaths)
开发者ID:ndawe,项目名称:scikit-timeseries,代码行数:28,代码来源:test_avcf.py


示例3: recache

    def recache(self, always=False):
        if always or self._invalidx:
            xconv = self.convert_xunits(self._xorig)
            if ma.isMaskedArray(self._xorig):
                x = ma.asarray(xconv, np.float_).filled(np.nan)
            else:
                x = np.asarray(xconv, np.float_)
            x = x.ravel()
        else:
            x = self._x
        if always or self._invalidy:
            yconv = self.convert_yunits(self._yorig)
            if ma.isMaskedArray(self._yorig):
                y = ma.asarray(yconv, np.float_).filled(np.nan)
            else:
                y = np.asarray(yconv, np.float_)
            y = y.ravel()
        else:
            y = self._y

        if len(x) == 1 and len(y) > 1:
            x = x * np.ones(y.shape, np.float_)
        if len(y) == 1 and len(x) > 1:
            y = y * np.ones(x.shape, np.float_)

        if len(x) != len(y):
            raise RuntimeError('xdata and ydata must be the same length')

        self._xy = np.empty((len(x), 2), dtype=np.float_)
        self._xy[:, 0] = x
        self._xy[:, 1] = y

        self._x = self._xy[:, 0]  # just a view
        self._y = self._xy[:, 1]  # just a view

        self._subslice = False
        if (self.axes and len(x) > 1000 and self._is_sorted(x) and
                self.axes.name == 'rectilinear' and
                self.axes.get_xscale() == 'linear' and
                self._markevery is None and
                self.get_clip_on() is True):
            self._subslice = True
            nanmask = np.isnan(x)
            if nanmask.any():
                self._x_filled = self._x.copy()
                indices = np.arange(len(x))
                self._x_filled[nanmask] = np.interp(indices[nanmask],
                        indices[~nanmask], self._x[~nanmask])
            else:
                self._x_filled = self._x

        if self._path is not None:
            interpolation_steps = self._path._interpolation_steps
        else:
            interpolation_steps = 1
        xy = STEP_LOOKUP_MAP[self._drawstyle](*self._xy.T)
        self._path = Path(np.asarray(xy).T, None, interpolation_steps)
        self._transformed_path = None
        self._invalidx = False
        self._invalidy = False
开发者ID:AbdealiJK,项目名称:matplotlib,代码行数:60,代码来源:lines.py


示例4: recache

    def recache(self, always=False):
        if always or self._invalidx:
            xconv = self.convert_xunits(self._xorig)
            if ma.isMaskedArray(self._xorig):
                x = ma.asarray(xconv, np.float_)
            else:
                x = np.asarray(xconv, np.float_)
            x = x.ravel()
        else:
            x = self._x
        if always or self._invalidy:
            yconv = self.convert_yunits(self._yorig)
            if ma.isMaskedArray(self._yorig):
                y = ma.asarray(yconv, np.float_)
            else:
                y = np.asarray(yconv, np.float_)
            y = y.ravel()
        else:
            y = self._y

        if len(x) == 1 and len(y) > 1:
            x = x * np.ones(y.shape, np.float_)
        if len(y) == 1 and len(x) > 1:
            y = y * np.ones(x.shape, np.float_)

        if len(x) != len(y):
            raise RuntimeError("xdata and ydata must be the same length")

        x = x.reshape((len(x), 1))
        y = y.reshape((len(y), 1))

        if ma.isMaskedArray(x) or ma.isMaskedArray(y):
            self._xy = ma.concatenate((x, y), 1)
        else:
            self._xy = np.concatenate((x, y), 1)
        self._x = self._xy[:, 0]  # just a view
        self._y = self._xy[:, 1]  # just a view

        self._subslice = False
        if (
            self.axes
            and len(x) > 100
            and self._is_sorted(x)
            and self.axes.name == "rectilinear"
            and self.axes.get_xscale() == "linear"
            and self._markevery is None
        ):
            self._subslice = True
        if hasattr(self, "_path"):
            interpolation_steps = self._path._interpolation_steps
        else:
            interpolation_steps = 1
        self._path = Path(self._xy, None, interpolation_steps)
        self._transformed_path = None
        self._invalidx = False
        self._invalidy = False
开发者ID:embray,项目名称:matplotlib,代码行数:56,代码来源:lines.py


示例5: __new__

    def __new__(cls, data=None, name=None, mask=None, fill_value=None,
                dtype=None, shape=(), length=0,
                description=None, unit=None, format=None, meta=None,
                units=None, dtypes=None):

        if dtypes is not None:
            dtype = dtypes
            warnings.warn("'dtypes' has been renamed to the singular 'dtype'.",
                          AstropyDeprecationWarning)

        if units is not None:
            unit = units
            warnings.warn("'units' has been renamed to the singular 'unit'.",
                          AstropyDeprecationWarning)

        if data is None:
            dtype = (np.dtype(dtype).str, shape)
            self_data = ma.zeros(length, dtype=dtype)
        elif isinstance(data, (Column, MaskedColumn)):
            self_data = ma.asarray(data.data, dtype=dtype)
            if description is None:
                description = data.description
            if unit is None:
                unit = unit or data.unit
            if format is None:
                format = data.format
            if meta is None:
                meta = deepcopy(data.meta)
            if name is None:
                name = data.name
        elif isinstance(data, Quantity):
            if unit is None:
                self_data = ma.asarray(data, dtype=dtype)
                unit = data.unit
            else:
                self_data = ma.asarray(data.to(unit), dtype=dtype)
        else:
            self_data = ma.asarray(data, dtype=dtype)

        self = self_data.view(MaskedColumn)
        if mask is None and hasattr(data, 'mask'):
            mask = data.mask
        if fill_value is None and hasattr(data, 'fill_value'):
            fill_value = data.fill_value
        self.mask = mask
        self.fill_value = fill_value
        self._name = name
        self.unit = unit
        self.format = format
        self.description = description
        self.parent_table = None
        self.meta = meta

        return self
开发者ID:astrodsg,项目名称:astropy,代码行数:54,代码来源:column.py


示例6: _check

 def _check(self, data):
     array = biggus.NumpyArrayAdapter(data)
     result = self.biggus_operator(array, axis=0).masked_array()
     expected = self.numpy_masked_operator(data, axis=0)
     if expected.ndim == 0:
         if expected is np.ma.masked:
             expected = ma.asarray(expected, dtype=array.dtype)
         else:
             expected = ma.asarray(expected)
     np.testing.assert_array_equal(result.filled(), expected.filled())
     np.testing.assert_array_equal(result.mask, expected.mask)
开发者ID:QuLogic,项目名称:biggus,代码行数:11,代码来源:_aggregation_test_framework.py


示例7: _mann_whitney_u

def _mann_whitney_u(x, y=None):
    """
    Calculate the Mann-Whitney-U test.

    The Wilcoxon signed-rank test tests the null hypothesis that two related paired 
    samples come from the same distribution. In particular, it tests whether the 
    distribution of the differences x - y is symmetric about zero. 
    It is a non-parametric version of the paired T-test.
    """
    # A significance-dict for a two-tailed test with 0.05 confidence
    # from http://de.wikipedia.org/wiki/Wilcoxon-Mann-Whitney-Test
    significance_table = \
    [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2],
    [0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8],
    [0, 0, 0, 0, 1, 2, 3, 4, 4, 5, 6, 7, 8, 9, 10, 11, 11, 12, 13, 14],
    [0, 0, 0, 0, 2, 3, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 17, 18, 19, 20],
    [0, 0, 0, 0, 0, 5, 6, 8, 10, 11, 13, 14, 16, 17, 19, 21, 22, 24, 25, 27],
    [0, 0, 0, 0, 0, 0, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34],
    [0, 0, 0, 0, 0, 0, 0, 13, 15, 17, 19, 22, 24, 26, 29, 31, 34, 36, 38, 41],
    [0, 0, 0, 0, 0, 0, 0, 0, 17, 20, 23, 26, 28, 31, 34, 37, 39, 42, 45, 48],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 26, 29, 33, 36, 39, 42, 45, 48, 52, 55],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 33, 37, 40, 44, 47, 51, 55, 58, 62],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37, 41, 45, 49, 53, 57, 61, 65, 69],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 45, 50, 54, 59, 63, 67, 72, 76],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 59, 64, 69, 74, 78, 83],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 70, 75, 80, 85, 90],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 75, 81, 86, 92, 98],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 87, 93, 99, 105],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99, 106, 112],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 113, 119],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127]]
    
    U, p = stats.mannwhitneyu(x, y)
    
    x = ma.asarray(x).compressed().view(numpy.ndarray)
    y = ma.asarray(y).compressed().view(numpy.ndarray)
    
    n1 = len(x)
    n2 = len(y)
    print n1, n2
    if n1 > n2:
        tmp = n2
        n2 = n1
        n1 = tmp
    
    if n1 < 5 or n2 < 5:
        return 10000, 10000
    if n1 < 20 or n2 < 20:
        print "WARNING: scipy.stat might not be accurate, p value is %f and significance according to table is %s" % \
                (p, U <= significance_table[n1 - 1][n2 - 1])
    return U, p
开发者ID:bjkomer,项目名称:HPOlib,代码行数:52,代码来源:statistics.py


示例8: test_masked_fill_value

 def test_masked_fill_value(self):
     cubes = []
     y = (0, 2)
     cube = _make_cube((0, 2), y, 1)
     cube.data = ma.asarray(cube.data)
     cube.data.fill_value = 10
     cubes.append(cube)
     cube = _make_cube((2, 4), y, 1)
     cube.data = ma.asarray(cube.data)
     cube.data.fill_value = 20
     cubes.append(cube)
     result = concatenate(cubes)
     self.assertEqual(len(result), 2)
开发者ID:TheClimateCorporation,项目名称:iris,代码行数:13,代码来源:test_concatenate.py


示例9: detect_contour

def detect_contour(img, level):
  """Returns list of vertices of contours at a given level
  
  Arguments:
    img (array): the image array
    level (number): the level at which to create the contour
  
  Returns:
    (list of nx2 arrays): list of list of vertices of the different contours
  
  Note:
    The contour detection is based on matplotlib's QuadContourGenerator
  """
  #parameter
  mask = None;
  corner_mask = True;
  nchunk = 0;

  #prepare image data
  z = ma.asarray(img, dtype=np.float64); 
  ny, nx = z.shape;
  x, y = np.meshgrid(np.arange(nx), np.arange(ny));

  #find contour
  contour_generator = _contour.QuadContourGenerator(x, y, z.filled(), mask, corner_mask, nchunk)
  vertices = contour_generator.create_contour(level);
  
  return vertices;
开发者ID:ChristophKirst,项目名称:CElegansBehaviour,代码行数:28,代码来源:contours_old.py


示例10: _expected

 def _expected(self, transpose=False):
     data = self.data
     if transpose:
         data = self.data.T
     # Expected raster weights per target grid cell.
     # This is the (fractional) source cell contribution
     # to each target cell (out of 255)
     weights = np.array([[[63, 127, 127],   # top left hand cell (tlhc)
                          [127, 255, 255]],
                         [[127, 127, 63],   # top right hand cell (trhc)
                          [255, 255, 127]],
                         [[127, 255, 255],  # bottom left hand cell (blhc)
                          [63, 127, 127]],
                         [[255, 255, 127],  # bottom right hand cell (brhc)
                          [127, 127, 63]]], dtype=np.uint8)
     weights = weights / 255
     # Expected source points per target grid cell.
     tmp = data[1:-1, 1:-1]
     shape = (-1, 2, 3)
     cells = [tmp[slice(0, 2), slice(0, 3)].reshape(shape),       # tlhc
              tmp[slice(0, 2), slice(3, None)].reshape(shape),    # trhc
              tmp[slice(2, None), slice(0, 3)].reshape(shape),    # blhc
              tmp[slice(2, None), slice(3, None)].reshape(shape)] # brhc
     cells = ma.vstack(cells)
     # Expected fractional weighted result.
     num = (cells * weights).sum(axis=(1, 2))
     dom = weights.sum(axis=(1, 2))
     expected = num / dom
     expected = ma.asarray(expected.reshape(2, 2))
     if transpose:
         expected = expected.T
     return expected
开发者ID:cpelley,项目名称:iris-agg-regrid,代码行数:32,代码来源:test_agg.py


示例11: smooth

    def smooth(self, Y):
        '''Run UKS

        Params
        ------
        Y : [T, n_dim_state] array
            Y[t] =  t obs
            If Y is a masked array and any Y[t] is masked, obs is assumed missing and ignored.

        Returns
        -------
        smoothed_state_means : [T, n_dim_state] array
            filtered_state_means[t] = mean of t state distribution | [0, T-1] obs
        smoothed_state_covariances : [T, n_dim_state, n_dim_state] array
            filtered_state_covariances[t] = covariance of t state distribution | [0, T-1] obs
        '''
        
        Y = ma.asarray(Y)

        (transition_functions, observation_functions,
         transition_covariance, observation_covariance,
         initial_state_mean, initial_state_covariance) = (
            self._initialize_parameters()
        )

        (filtered_state_means, filtered_state_covariances) = self.filter(Y)
        (smoothed_state_means, smoothed_state_covariances) = (
            additive_unscented_smoother(
                filtered_state_means, filtered_state_covariances,
                transition_functions, transition_covariance
            )
        )

        return (smoothed_state_means, smoothed_state_covariances)
开发者ID:PierrotLC,项目名称:UnscentedKalmanFilter,代码行数:34,代码来源:UKF.py


示例12: __call__

    def __call__(self, value, clip=None, midpoint=None):


        if clip is None:
            clip = self.clip

        if cbook.iterable(value):
            vtype = 'array'
            val = ma.asarray(value).astype(np.float)
        else:
            vtype = 'scalar'
            val = ma.array([value]).astype(np.float)

        self.autoscale_None(val)
        vmin, vmax = self.vmin, self.vmax

        if vmin > vmax:
            raise ValueError("minvalue must be less than or equal to maxvalue")
        elif vmin==vmax:
            return 0.0 * val
        else:
            if clip:
                mask = ma.getmask(val)
                val = ma.array(np.clip(val.filled(vmax), vmin, vmax),
                                mask=mask)
            result = (val-vmin) * (1.0/(vmax-vmin))
            #result = (ma.arcsinh(val)-np.arcsinh(vmin))/(np.arcsinh(vmax)-np.arcsinh(vmin))
            result = result**(1./self.nthroot)
        if vtype == 'scalar':
            result = result[0]
        return result
开发者ID:Fade89,项目名称:agpy,代码行数:31,代码来源:sqrt_norm.py


示例13: __call__

    def __call__(self, value, clip=None):
        if clip is None:
            clip = self.clip

        if cbook.iterable(value):
            vtype = 'array'
            val = ma.asarray(value).astype(np.float)
        else:
            vtype = 'scalar'
            val = ma.array([value]).astype(np.float)

        self.autoscale_None(val)
        vmin, vmax = self.vmin, self.vmax
        if vmin > vmax:
            raise ValueError("minvalue must be less than or equal to maxvalue")
        elif vmin<=0:
            raise ValueError("values must all be positive")
        elif vmin==vmax:
            return 0.0 * val
        else:
            if clip:
                mask = ma.getmask(val)
                val = ma.array(np.clip(val.filled(vmax), vmin, vmax),
                                mask=mask)
            result = (ma.log(val)-np.log(vmin))/(np.log(vmax)-np.log(vmin))
        if vtype == 'scalar':
            result = result[0]
        return result
开发者ID:AndreI11,项目名称:SatStressGui,代码行数:28,代码来源:colors.py


示例14: __call__

 def __call__(self, value, clip=None):
     if clip is None:
         clip = self.clip
     if cbook.iterable(value):
         vtype = 'array'
         val = ma.asarray(value).astype(np.float)
     else:
         vtype = 'scalar'
         val = ma.array([value]).astype(np.float)
     self.autoscale_None(val)
     vmin, vmax = self.vmin, self.vmax
     cmin, cmax = self.cmin * vmin, self.cmax * vmax
     if vmin > vmax:
         raise ValueError("minvalue must be less than or equal to maxvalue")
     elif vmin == vmax:
         result = 0.0 * val
     else:
         if clip:
             mask = ma.getmask(val)
             val = ma.array(np.clip(val.filled(vmax), vmin, vmax),
                             mask=mask)
         result = 0. * val + 0.5
         result[val > cmax] = (ma.log10(val[val > cmax]) - ma.log10(cmax)) / (np.log10(vmax) - np.log10(cmax)) / 2. + 0.5
         result[val < cmin] = -(ma.log10(-val[val < cmin]) - ma.log10(-cmin)) / (np.log10(-vmin) - np.log10(-cmin)) / 2. + 0.5
     if vtype == 'scalar':
         result = result[0]
     return result
开发者ID:iceseismic,项目名称:sito,代码行数:27,代码来源:imaging.py


示例15: set_data

 def set_data(self, x, y, A):
     x = np.asarray(x, np.float32)
     y = np.asarray(y, np.float32)
     A = ma.asarray(A)
     if len(x.shape) != 1 or len(y.shape) != 1\
        or A.shape[0:2] != (y.shape[0], x.shape[0]):
         raise TypeError("Axes don't match array shape")
     if len(A.shape) not in [2, 3]:
         raise TypeError("Can only plot 2D or 3D data")
     if len(A.shape) == 3 and A.shape[2] not in [1, 3, 4]:
         raise TypeError(
             "3D arrays must have three (RGB) or "
             "four (RGBA) color components"
             )
     if len(A.shape) == 3 and A.shape[2] == 1:
         A.shape = A.shape[0:2]
     if len(A.shape) == 2:
         if A.dtype != np.uint8:
             A = (self.cmap(self.norm(A)) * 255).astype(np.uint8)
         else:
             A = np.repeat(A[:, :, np.newaxis], 4, 2)
             A[:, :, 3] = 255
     else:
         if A.dtype != np.uint8:
             A = (255 * A).astype(np.uint8)
         if A.shape[2] == 3:
             B = np.zeros(tuple(list(A.shape[0:2]) + [4]), np.uint8)
             B[:, :, 0:3] = A
             B[:, :, 3] = 255
             A = B
     self._A = A
     self._Ax = x
     self._Ay = y
     self._imcache = None
开发者ID:GitEdit,项目名称:pyphant1,代码行数:34,代码来源:NonUniformImage.py


示例16: __call__

    def __call__(self, value, clip=None):
        if clip is None:
            clip = self.clip

        if cbook.iterable(value):
            vtype = 'array'
            val = ma.asarray(value).astype(numpy.float)
        else:
            vtype = 'scalar'
            val = ma.array([value]).astype(numpy.float)
        
        if self.staticrange is None:
            self.autoscale_None(val)
            vmin, vmax = self.vmin, self.vmax
        else:
            self.vmin, self.vmax = None, None
            self.autoscale_None(val)
            vmin, vmax = self.vmax - self.staticrange, self.vmax
        if vmin > vmax:
            raise ValueError("minvalue must be less than or equal to maxvalue")
        elif vmin==vmax:
            result = 0.0 * val
        else:
            vmin = float(vmin)
            vmax = float(vmax)
            rmin = float(self.rmin)
            rmax = float(self.rmax)
            if clip:
                mask = ma.getmask(val)
                val = ma.array(np.clip(val.filled(vmax), vmin, vmax),
                                mask=mask)
            result = (val-vmin) * ((rmax-rmin) / (vmax-vmin)) + rmin
        if vtype == 'scalar':
            result = result[0]
        return result
开发者ID:priyom,项目名称:priyomdb,代码行数:35,代码来源:vorbis-to-spectrum.py


示例17: sim

def sim():
    np.random.seed(1)

    # Generate the time vector
    dt = 0.05
    N = int(30 // dt)
    k = np.arange(N)
    t = k * dt

    # Instantiate the model
    given = dict(
        alpha=1, beta=-1, delta=0.2, gamma=0.3, omega=1,
        g1=0, g2=0.1, x_meas_std=0.1,
        x0=1, v0=0, x0_std=0.1, v0_std=0.1
    )
    q = GeneratedDTDuffing.pack('q', given)
    c = GeneratedDTDuffing.pack('c', given)
    params = dict(q=q, c=c, dt=dt)
    sampled = dict(t=t)
    model = GeneratedDTDuffing(params, sampled)

    # Simulate the system
    w = np.random.randn(N - 1, model.nw)
    x = np.zeros((N, model.nx))
    x[0] = stats.multivariate_normal.rvs(model.x0(), model.Px0())
    for k in range(N - 1):
        x[k + 1] = model.f(k, x[k])  + model.g(k, x[k]).dot(w[k])
    
    # Sample the outputs
    R = model.R()
    v = np.random.multivariate_normal(np.zeros(model.ny), R, N)
    y = ma.asarray(model.h(k, x) + v)
    y[np.arange(N) % 4 != 0] = ma.masked
    return model, t, x, y, q
开发者ID:dimasad,项目名称:ceacoest,代码行数:34,代码来源:duffing.py


示例18: to_rgba

 def to_rgba(self, x, alpha=None, bytes=False):
     '''Return a normalized rgba array corresponding to *x*. If *x*
     is already an rgb array, insert *alpha*; if it is already
     rgba, return it unchanged. If *bytes* is True, return rgba as
     4 uint8s instead of 4 floats.
     '''
     if alpha is None:
         _alpha = 1.0
     else:
         _alpha = alpha
     try:
         if x.ndim == 3:
             if x.shape[2] == 3:
                 if x.dtype == np.uint8:
                     _alpha = np.array(_alpha*255, np.uint8)
                 m, n = x.shape[:2]
                 xx = np.empty(shape=(m,n,4), dtype = x.dtype)
                 xx[:,:,:3] = x
                 xx[:,:,3] = _alpha
             elif x.shape[2] == 4:
                 xx = x
             else:
                 raise ValueError("third dimension must be 3 or 4")
             if bytes and xx.dtype != np.uint8:
                 xx = (xx * 255).astype(np.uint8)
             return xx
     except AttributeError:
         pass
     x = ma.asarray(x)
     x = self.norm(x)
     x = self.cmap(x, alpha=alpha, bytes=bytes)
     return x
开发者ID:AlexSzatmary,项目名称:matplotlib,代码行数:32,代码来源:cm.py


示例19: bodytrack

def bodytrack(threadstuple, serv):
    #serv_M = ma.asarray([[0, 0, 0, 0, 6983544, 91465, 23131612, 171783],
    #                     [340208, 21308, 230049, 18250, 83687, 35901, 0, 0],
    #                     [0, 0, 0, 0, 0, 0, 22032093, 103155]])
    serv_M = ma.asarray(serv)

    rout = [
        [[0, 0, 0, 0],
         [0, 0, 0, 0],
         [0, 0, 1, 1],
         [0, 0, 1, 0]],
         [[39, 1, 0, 0],
          [0, 4, 1, 0],
          [1, 0, 1, 0],
          [0, 0, 0, 0]],
        [[0, 0, 0, 0],
         [0, 0, 0, 0],
         [0, 0, 0, 0],
         [0, 0, 0, 1]]
         ]

    qt = list(islice(cycle((1,0)), serv_M.shape[1]))
    routL = map (lambda x: rout_insert_inter(normalizeRowWise(np.asarray(x))), rout)
    res = mva_multiclass (routL, 1./serv_M.T, threadstuple, qt)
    cont = (res[0][1::2] - serv_M.T[1::2]).T
    print "%.0f %.0f %.0f" % (cont[1,0], cont[0,2], cont[2,3])

    return res
开发者ID:SLAP-,项目名称:locklocklock,代码行数:28,代码来源:lockgraph.py


示例20: process_value

    def process_value(value):
        """
        Homogenize the input *value* for easy and efficient normalization.

        *value* can be a scalar or sequence.

        Returns *result*, *is_scalar*, where *result* is a
        masked array matching *value*.  Float dtypes are preserved;
        integer types with two bytes or smaller are converted to
        np.float32, and larger types are converted to np.float.
        Preserving float32 when possible, and using in-place operations,
        can greatly improve speed for large arrays.

        Experimental; we may want to add an option to force the
        use of float32.
        """
        if cbook.iterable(value):
            is_scalar = False
            result = ma.asarray(value)
            if result.dtype.kind == 'f':
                if isinstance(value, np.ndarray):
                    result = result.copy()
            elif result.dtype.itemsize > 2:
                result = result.astype(np.float)
            else:
                result = result.astype(np.float32)
        else:
            is_scalar = True
            result = ma.array([value]).astype(np.float)
        return result, is_scalar
开发者ID:aseagram,项目名称:matplotlib,代码行数:30,代码来源:colors.py



注:本文中的numpy.ma.asarray函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python ma.average函数代码示例发布时间:2022-05-27
下一篇:
Python ma.array函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap