当前位置: 首页>>代码示例>>Python>>正文


Python multiarray.array函数代码示例

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


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

示例1: get_dataframe

    def get_dataframe(self, attr, measure='mean', sum=False, cum=False):
        """
        :rtype NDFrame
        """
        values = []
        for name in self.names:
            market_periods_by_date = self.periods_by_market_and_date[name]
            values.append([market_periods_by_date[date][attr] for date in self.dates])

        values = array(values)  # shape is names-dates-samples

        if cum:
            # Accumulate over the dates, the second axis.
            # shape is the same: names-dates-samples
            values = values.cumsum(axis=1)

        if sum:
            # Sum over the names, the first axis.
            # shape is dates-samples
            values = values.sum(axis=0)
            pass

        if measure == 'mean':
            values = values.mean(axis=-1)
        elif measure == 'std':
            values = values.std(axis=-1)
        elif measure == 'quantile':
            assert self.confidence_interval is not None
            low_percentile = (100 - self.confidence_interval) / 2.0
            high_percentile = 100 - low_percentile
            mean = values.mean(axis=-1)
            low = mean - nanpercentile(values, q=low_percentile, axis=-1)
            high = nanpercentile(values, q=high_percentile, axis=-1) - mean
            errors = []
            if sum:
                # Need to return 2-len(dates) sized array, for a Series.
                errors.append([low, high])
            else:
                # Need to return len(names)-2-len(dates) sized array, for a DateFrame.
                for i in range(len(self.names)):
                    errors.append([low[i], high[i]])
            values = array(errors)
            return values
        # elif measure == 'direct':
        #     raise NotImplementedError()
        #     if len(values) == 1:
        #         values = values[0]
        #     else:
        #         raise NotImplementedError()
        #     return DataFrame(values, index=dates, columns=names)
        else:
            raise Exception("Measure '{}' not supported".format(measure))

        if sum:
            return Series(values, index=self.dates)
        else:
            return DataFrame(values.T, index=self.dates, columns=self.names)
开发者ID:johnbywater,项目名称:quantdsl,代码行数:57,代码来源:results.py

示例2: kraus_to_choi

def kraus_to_choi(kraus_list):
    """
    Takes a list of Kraus operators and returns the Choi matrix for the channel
    represented by the Kraus operators in `kraus_list`
    """
    kraus_mat_list = list(map(lambda x: matrix(x.data.todense()), kraus_list))
    op_len = len(kraus_mat_list[0])
    op_rng = range(op_len)
    choi_blocks = array([[sum([op[:, c_ix] * array([op.H[r_ix, :]])
                               for op in kraus_mat_list])
                          for r_ix in op_rng]
                         for c_ix in op_rng])
    return Qobj(inpt=hstack(hstack(choi_blocks)),
                dims=[kraus_list[0].dims, kraus_list[0].dims])
开发者ID:vprusso,项目名称:qutip,代码行数:14,代码来源:superop_reps.py

示例3: bincount

def bincount(x, weights=None, minlength=None):
    if minlength is None:
        minlength = 0
    else:
        if not isinstance(minlength, (int, long)):
            raise TypeError("an integer is required")
        if minlength <= 0:
            raise ValueError("minlength must be positive")

    x = array(x)
    len_output = minlength
    if len(x) > 0:
        if x.min() < 0:
            raise ValueError("x must not be negative")
        len_output = max(len_output, x.max() + 1)

    if x.dtype.kind not in 'ui':
        raise ValueError("x must be integer")

    if weights is None:
        output = zeros(len_output, dtype=dtype('int'))
        for elem in x:
            output[elem] += 1
    else:
        if len(weights) != len(x):
            raise ValueError("x and weights arrays must have the same size")
        output = zeros(len_output, dtype=dtype('float'))
        for i in range(len(x)):
            output[x[i]] += weights[i]
    return output
开发者ID:k3331863,项目名称:IR2,代码行数:30,代码来源:bincount.py

示例4: default

  def default(self):
    'Base controller for application.'
    readings = self._read_logfile()
    self.readings_array = array(readings)[:, 0]

    self._print_distribution_stats()
    self._print_histogram('Full distribution histogram')
    self._print_zoom_histograms()
开发者ID:xchewtoyx,项目名称:histogram,代码行数:8,代码来源:histogram.py

示例5: choi_to_kraus

def choi_to_kraus(q_oper):
    """
    Takes a Choi matrix and returns a list of Kraus operators.
    TODO: Create a new class structure for quantum channels, perhaps as a
    strict sub-class of Qobj.
    """
    vals, vecs = eig(q_oper.data.todense())
    vecs = [array(_) for _ in zip(*vecs)]
    return [Qobj(inpt=sqrt(val)*vec2mat(vec)) for val, vec in zip(vals, vecs)]
开发者ID:MichalKononenko,项目名称:qutip,代码行数:9,代码来源:superop_reps.py

示例6: reverse_3

def reverse_3(input, original):
    original= array(original)
#ideally, we would have a recursive function that 
#would calculate four indices based on the top left corner
#and then calculate the rest, but I take the simple route 
    noise = input - original
    smallsquare = noise[:noise.shape[0]/float(2),:noise.shape[1]/float(2)]
    byrow = append(smallsquare, smallsquare, 0)
    bycolumnrow = append(byrow, byrow, 1)
    clean = input-bycolumnrow
    return clean
开发者ID:caijim,项目名称:Repo,代码行数:11,代码来源:q1client.py

示例7: getMostSevereValue

 def getMostSevereValue(self, minNInstants=1): # TODO use np.percentile
     from matplotlib.mlab import find
     from numpy.core.multiarray import array
     from numpy.core.fromnumeric import mean
     values = array(self.values.values())
     indices = range(len(values))
     if len(indices) >= minNInstants:
         values = sorted(values[indices], reverse = self.mostSevereIsMax) # inverted if most severe is max -> take the first values
         return mean(values[:minNInstants])
     else:
         return None
开发者ID:Transience,项目名称:buffer,代码行数:11,代码来源:indicators.py

示例8: build_selection_matrix

def build_selection_matrix(results, teams):
    matrix = []

    for result in results:
        index_a, index_b = teams[result['teamHome']], teams[result['teamAway']]
        line = [0] * len(teams)
        line[index_a] = 1
        line[index_b] = -1

        matrix.append(line)

    return array(matrix)
开发者ID:kryptBlue,项目名称:soccer-stats-backend,代码行数:12,代码来源:calc.py

示例9: draw_pz

    def draw_pz(self, tfcn):
        """Draw pzmap"""
        self.f_pzmap.clf()
        # Make adaptive window size, with min [-10, 10] in range,
        # always atleast 25% extra space outside poles/zeros
        tmp = list(self.zeros)+list(self.poles)+[8]
        val = 1.25*max(abs(array(tmp)))
        plt.figure(self.f_pzmap.number)
        control.matlab.pzmap(tfcn)
        plt.suptitle('Pole-Zero Diagram')

        plt.axis([-val, val, -val, val])
开发者ID:alchemyst,项目名称:python-control,代码行数:12,代码来源:tfvis.py

示例10: _dep_super

def _dep_super(pe):
    """
    Returns the superoperator corresponding to qubit depolarization for a
    given parameter pe.

    TODO: if this is going into production (hopefully it isn't) then check
    CPTP, expand to arbitrary dimensional systems, etc.
    """
    return Qobj(dims=[[[2], [2]], [[2], [2]]],
                inpt=array([[1. - pe / 2., 0., 0., pe / 2.],
                            [0., 1. - pe, 0., 0.],
                            [0., 0., 1. - pe, 0.],
                            [pe / 2., 0., 0., 1. - pe / 2.]]))
开发者ID:JonathanUlm,项目名称:qutip,代码行数:13,代码来源:superop_reps.py

示例11: convert_props

    def convert_props(self, real_props=None, fake_props=None):
        new_props = []
        if real_props is not None:
            if len(real_props) > 0:
                assert isinstance(real_props[0], ThreatEnvironmentProperties)
                for real_prop in real_props:
                    assert isinstance(real_prop, ThreatEnvironmentProperties)
                    assert len(real_prop.theProperties) == len(real_prop.theRationale)
                    new_attrs = []
                    for idx in range(0, len(real_prop.theProperties)):
                        attr_name = self.rev_attr_dict.get(idx)
                        attr_value = self.prop_dict[real_prop.theProperties[idx]]
                        attr_rationale = real_prop.theRationale[idx]
                        new_attr = SecurityAttribute(attr_name, attr_value, attr_rationale)
                        new_attrs.append(new_attr)
                    real_prop.theProperties = new_attrs
                    new_props.append(real_prop)

            return new_props
        elif fake_props is not None:
            if len(fake_props) > 0:
                check_required_keys(fake_props[0], ThreatEnvironmentPropertiesModel.required)
                for fake_prop in fake_props:
                    check_required_keys(fake_prop, ThreatEnvironmentPropertiesModel.required)
                    new_ndprops = array([0]*8).astype(numpy.core.int32)
                    new_ratios = ['None']*8
                    for idx in range(0, len(fake_prop['theProperties'])):
                        new_attr = fake_prop['theProperties'][idx]
                        check_required_keys(new_attr, SecurityAttribute.required)
                        attr_id = self.attr_dict.get(new_attr['name'], -1)
                        if -1 < attr_id < len(self.attr_dict):
                            attr_value = self.rev_prop_dict[new_attr['value']]
                            attr_rationale = new_attr['rationale']
                            new_ndprops[attr_id] = attr_value
                            new_ratios[attr_id] = attr_rationale
                    fake_prop['theProperties'] = new_ndprops
                    fake_prop['theRationale'] = new_ratios
                    new_prop = ThreatEnvironmentProperties(
                        environmentName=fake_prop['theEnvironmentName'],
                        lhood=fake_prop['theLikelihood'],
                        assets=fake_prop['theAssets'],
                        attackers=fake_prop['theAttackers'],
                        pRationale=fake_prop['theRationale'],
                        syProperties=fake_prop['theProperties']
                    )
                    new_props.append(new_prop)

            return new_props
        else:
            self.close()
            raise MissingParameterHTTPError(param_names=['real_props', 'fake_props'])
开发者ID:RachelLar,项目名称:CAIRIS-web,代码行数:51,代码来源:ThreatDAO.py

示例12: _generalized_kraus

def _generalized_kraus(q_oper, thresh=1e-10):
    # TODO: document!
    # TODO: use this to generalize to_kraus to the case where U != V.
    #       This is critical for non-CP maps, as appear in (for example)
    #       diamond norm differences between two CP maps.
    if q_oper.type != "super" or q_oper.superrep != "choi":
        raise ValueError("Expected a Choi matrix, got a {} (superrep {}).".format(q_oper.type, q_oper.superrep))
    
    # Remember the shape of the underlying space,
    # as we'll need this to make Kraus operators later.
    dL, dR = map(int, map(sqrt, q_oper.shape))
    # Also remember the dims breakout.
    out_dims, in_dims = q_oper.dims
    out_left, out_right = out_dims
    in_left, in_right = in_dims

    # Find the SVD.
    U, S, V = svd(q_oper.data.todense())

    # Truncate away the zero singular values, up to a threshold.
    nonzero_idxs = S > thresh
    dK = nonzero_idxs.sum()
    U = array(U)[:, nonzero_idxs]
    # We also want S to be a single index array, which np.matrix
    # doesn't allow for. This is stripped by calling array() on it.
    S = sqrt(array(S)[nonzero_idxs])
    # Since NumPy returns V and not V+, we need to take the dagger
    # to get back to quantum info notation for Stinespring pairs.
    V = array(V.conj().T)[:, nonzero_idxs]

    # Next, we convert each of U and V into Kraus operators.
    # Finally, we want the Kraus index to be left-most so that we
    # can map over it when making Qobjs.
    # FIXME: does not preserve dims!
    kU = _svd_u_to_kraus(U, S, dL, dK, out_right, out_left)
    kV = _svd_u_to_kraus(V, S, dL, dK, in_right, in_left)

    return kU, kV
开发者ID:kaze-sakai,项目名称:qutip,代码行数:38,代码来源:superop_reps.py

示例13: _svd_u_to_kraus

def _svd_u_to_kraus(U, S, d, dK, indims, outdims):
    """
    Given a partial isometry U and a vector of square-roots of singular values S
    obtained from an SVD, produces the Kraus operators represented by U.

    Returns
    -------
    Ks : list of Qobj
        Quantum objects represnting each of the Kraus operators.
    """
    # We use U * S since S is 1-index, such that this is equivalent to
    # U . diag(S), but easier to write down.
    Ks = list(map(Qobj, array(U * S).reshape((d, d, dK), order='F').transpose((2, 0, 1))))
    for K in Ks:
        K.dims = [outdims, indims]
    return Ks
开发者ID:kaze-sakai,项目名称:qutip,代码行数:16,代码来源:superop_reps.py

示例14: indicatorMapFromPolygon

def indicatorMapFromPolygon(value, polygon, squareSize):
    '''Fills an indicator map with the value within the polygon
    (array of Nx2 coordinates of the polygon vertices)'''
    import matplotlib.nxutils as nx
    from numpy.core.multiarray import array, arange
    from numpy import floor

    points = []
    for x in arange(min(polygon[:,0])+squareSize/2, max(polygon[:,0]), squareSize):
        for y in arange(min(polygon[:,1])+squareSize/2, max(polygon[:,1]), squareSize):
            points.append([x,y])
    inside = nx.points_inside_poly(array(points), polygon)
    indicatorMap = {}
    for i in xrange(len(inside)):
        if inside[i]:
            indicatorMap[(floor(points[i][0]/squareSize), floor(points[i][1]/squareSize))] = 0
    return indicatorMap
开发者ID:Transience,项目名称:buffer,代码行数:17,代码来源:indicators.py

示例15: convert_props

 def convert_props(self, real_props=None, fake_props=None, rationales=None):
   prop_dict = {}
   prop_dict['None'] = 0
   prop_dict['Low'] = 1
   prop_dict['Medium'] = 2
   prop_dict['High'] = 3
   rev_prop_dict = {}
   rev_prop_dict[0] = 'None'
   rev_prop_dict[1] = 'Low'
   rev_prop_dict[2] = 'Medium'
   rev_prop_dict[3] = 'High'
   new_props = []
   if real_props is not None:
     if len(real_props) > 0:
       new_sec_attrs = []
       for idx in range(0, len(real_props)):
         try:
           attr_name = self.rev_attr_dict[idx]
           attr_value = rev_prop_dict[real_props[idx]]
           new_sec_attr = SecurityAttribute(attr_name, attr_value, rationales[idx])
           new_props.append(new_sec_attr)
         except LookupError:
           self.logger.warning('Unable to find key in dictionary. Attribute is being skipped.')
     return new_props
   elif fake_props is not None:
     if len(fake_props) > 0:
       new_props = array(8 * [0]).astype(numpy.int32)
       new_rationale = ['None'] * 8
       for sec_attr in fake_props:
         attr_id = self.attr_dict[sec_attr['name']]
         attr_value = prop_dict[sec_attr['value']]
         attr_rationale = sec_attr['rationale']
         new_props[attr_id] = attr_value
         new_rationale[attr_id] = attr_rationale
     return (new_props,new_rationale)
   else:
     self.close()
     raise MissingParameterHTTPError(param_names=['real_props', 'fake_props'])
开发者ID:failys,项目名称:cairis,代码行数:38,代码来源:TemplateAssetDAO.py


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