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

Python numpy.unique函数代码示例

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

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



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

示例1: check_classifiers_classes

def check_classifiers_classes(name, Classifier):
    X, y = make_blobs(n_samples=30, random_state=0, cluster_std=0.1)
    X, y = shuffle(X, y, random_state=7)
    X = StandardScaler().fit_transform(X)
    # We need to make sure that we have non negative data, for things
    # like NMF
    X -= X.min() - .1
    y_names = np.array(["one", "two", "three"])[y]

    for y_names in [y_names, y_names.astype('O')]:
        if name in ["LabelPropagation", "LabelSpreading"]:
            # TODO some complication with -1 label
            y_ = y
        else:
            y_ = y_names

        classes = np.unique(y_)
        # catch deprecation warnings
        with warnings.catch_warnings(record=True):
            classifier = Classifier()
        if name == 'BernoulliNB':
            classifier.set_params(binarize=X.mean())
        set_fast_parameters(classifier)
        # fit
        classifier.fit(X, y_)

        y_pred = classifier.predict(X)
        # training set performance
        assert_array_equal(np.unique(y_), np.unique(y_pred))
        if np.any(classifier.classes_ != classes):
            print("Unexpected classes_ attribute for %r: "
                  "expected %s, got %s" %
                  (classifier, classes, classifier.classes_))
开发者ID:AlexMarshall011,项目名称:scikit-learn,代码行数:33,代码来源:estimator_checks.py


示例2: by_lblimg

    def by_lblimg(self, lbldata):
        """
        Get specific template regions by rois given by user
        All regions overlapped with a specific label region will be covered

        Parameters:
        -----------
        lbldata: rois given by user

        Return:
        -------
        out_template: new template contains part of regions
                      if lbldata has multiple different rois, then new template will extract regions with each of roi given by user

        Example:
        --------
        >>> glr_cls = GetLblRegion(template)
        >>> out_template = glr_cls.by_lblimg(lbldata)
        """
        assert lbldata.shape == self._template.shape, "the shape of template should be equal to the shape of lbldata"
        labels = np.sort(np.unique(lbldata)[1:]).astype('int')
        out_template = np.zeros_like(lbldata)
        out_template = out_template[...,np.newaxis]
        out_template = np.tile(out_template, (1, len(labels)))
        for i,lbl in enumerate(labels):
            lbldata_tmp = tools.get_specificroi(lbldata, lbl)
            lbldata_tmp[lbldata_tmp!=0] = 1
            part_template = self._template*lbldata_tmp
            template_lbl = np.sort(np.unique(part_template)[1:])
            out_template[...,i] = tools.get_specificroi(self._template, template_lbl)
        return out_template
开发者ID:helloTC,项目名称:ATT,代码行数:31,代码来源:surf_tools.py


示例3: _pick_sources

    def _pick_sources(self, data, include, exclude, eid):
        """Aux method."""
        fast_dot = _get_fast_dot()
        if exclude is None:
            exclude = self.exclude
        else:
            exclude = list(set(list(self.exclude) + list(exclude)))

        logger.info('Transforming to Xdawn space')

        # Apply unmixing
        sources = fast_dot(self.filters_[eid].T, data)

        if include not in (None, []):
            mask = np.ones(len(sources), dtype=np.bool)
            mask[np.unique(include)] = False
            sources[mask] = 0.
            logger.info('Zeroing out %i Xdawn components' % mask.sum())
        elif exclude not in (None, []):
            exclude_ = np.unique(exclude)
            sources[exclude_] = 0.
            logger.info('Zeroing out %i Xdawn components' % len(exclude_))
        logger.info('Inverse transforming to sensor space')
        data = fast_dot(self.patterns_[eid], sources)

        return data
开发者ID:vwyart,项目名称:mne-python,代码行数:26,代码来源:xdawn.py


示例4: makeThresholdMap

def makeThresholdMap(image, findCars, scales=[1.5], percentOfHeapmapToToss=.5):
    print("scales:", scales, ", type:", type(scales), "image.shape:", image.shape, ", dtype:", image.dtype, ", percentOfHeapmapToToss:", percentOfHeapmapToToss)
    boundingBoxList=[]
    boundingBoxWeights=[]
    for scale in scales:
        listOfBoundingBoxes, listOfWeights = findCars(image, scale)
        boundingBoxList+=listOfBoundingBoxes
        boundingBoxWeights+=listOfWeights

    if USEBOUNDINGBOXWEIGHTS:
        unNormalizedHeatMap=addWeightedHeat(image.shape, boundingBoxList, boundingBoxWeights)
    else:
        unNormalizedHeatMap=addHeat(image.shape, boundingBoxList)

    if USESTACKOFHEATMAPS:
        unNormalizedHeatMap,_=totalHeatmapStack(unNormalizedHeatMap)


    unNormalizedHeatMapCounts=np.unique(unNormalizedHeatMap, return_counts=True)
    if TESTING: print("makeThresholdMap-unNormalizedHeatMapCounts:", unNormalizedHeatMapCounts, ", len(unNormalizedHeatMapCounts):", len(unNormalizedHeatMapCounts), ", len(unNormalizedHeatMapCounts[0]):", len(unNormalizedHeatMapCounts[0]))
    unNormalizedHeatMapMidpoint=unNormalizedHeatMapCounts[0][int(round(len(unNormalizedHeatMapCounts[0])*percentOfHeapmapToToss))]
    thresholdMap=applyThreshold(unNormalizedHeatMap, unNormalizedHeatMapMidpoint)
    print("makeThresholdMap-max(thresholdMap):", np.max(thresholdMap), ", min(thresholdMap):", np.min(thresholdMap))
    if TESTING: print("makeThresholdMap-thresholdMap counts:", (np.unique(thresholdMap, return_counts=True)), ", len(thresholdMap):", len(thresholdMap), ", len(thresholdMap[0]):", len(thresholdMap[0]))
    normalizedMap=normalizeMap(thresholdMap)
    if TESTING: print("makeThresholdMap-normalizedMap counts:", (np.unique(normalizedMap, return_counts=True)), ", len(normalizedMap):", len(normalizedMap), ", len(normalizedMap[0]):", len(normalizedMap[0]))
    print("makeThresholdMap-max(normalizedMap):", np.max(normalizedMap), ", min(normalizedMap):", np.min(normalizedMap))
    return normalizedMap, boundingBoxList, unNormalizedHeatMap, boundingBoxWeights
开发者ID:autohandle,项目名称:CarNdVehicleDetection-,代码行数:28,代码来源:FindCars.py


示例5: plot_decision_regions

def plot_decision_regions(X, y, classifier, test_idx=None, resolution=0.02):
    # setup marker generator and color map
    markers = ('s', 'x', 'o', '^', 'v')
    colors = ('red', 'blue', 'lightgreen', 'gray', 'cyan')
    cmap = ListedColormap(colors[:len(np.unique(y))])

    # plot the decision surface
    x1_min, x1_max = X[:, 0].min() - 1, X[:, 0].max() + 1
    x2_min, x2_max = X[:, 1].min() - 1, X[:, 1].max() + 1
    xx1, xx2 = np.meshgrid(np.arange(x1_min, x1_max, resolution),
                           np.arange(x2_min, x2_max, resolution))
    Z = classifier.predict(np.array([xx1.ravel(), xx2.ravel()]).T)
    Z = Z.reshape(xx1.shape)
    plt.contourf(xx1, xx2, Z, alpha=0.4, cmap=cmap)
    plt.xlim(xx1.min(), xx1.max())
    plt.ylim(xx2.min(), xx2.max())

    # plot class samples
    for idx, cl in enumerate(np.unique(y)):
        plt.scatter(x=X[y == cl, 0], y=X[y == cl, 1],
                    alpha=0.8, c=cmap(idx),
                    marker=markers[idx], label=cl)

    # Highlight test samples
    if test_idx:
        X_test, y_test = X[test_idx, :], y[test_idx]
        plt.scatter(X_test[:, 0],
                    X_test[:, 1],
                    c='',
                    alpha=1.0,
                    linewidths=1,
                    marker='o',
                    s=55, label='test set')
开发者ID:louishenrifranc,项目名称:MachineLearning,代码行数:33,代码来源:SVM.py


示例6: seems_like_discrete_data

def seems_like_discrete_data(arr, dictionary=None):
	if numpy.issubdtype(arr.dtype, numpy.bool_):
		#print('seems_like_discrete_data? YES bool')
		return True
	else:
		pass
		#print('seems_like_discrete_data? not bool but',arr.dtype)
	if dictionary is None:
		if len(numpy.unique(arr[:100]))<6:
			if len(numpy.unique(arr[:1000])) < 6:
				if len(numpy.unique(arr)) < 6:
					#print('seems_like_discrete_data? YES uniques < 6')
					return True
		#print('seems_like_discrete_data? too many and no dictionary')
	else:
		uniq = numpy.unique(arr)
		not_in_dict = 0
		for i in uniq:
			if i not in dictionary:
				not_in_dict += 1
		if not_in_dict > 2:
			#print(f'seems_like_discrete_data? dictionary but {not_in_dict} missing keys')
			return False
		else:
			#print(f'seems_like_discrete_data? dictionary with {not_in_dict} missing keys')
			return True
	return False
开发者ID:jpn--,项目名称:larch,代码行数:27,代码来源:histograms.py


示例7: test_value_counts_inferred

    def test_value_counts_inferred(self):
        klasses = [Index, Series]
        for klass in klasses:
            s_values = ['a', 'b', 'b', 'b', 'b', 'c', 'd', 'd', 'a', 'a']
            s = klass(s_values)
            expected = Series([4, 3, 2, 1], index=['b', 'a', 'd', 'c'])
            tm.assert_series_equal(s.value_counts(), expected)

            if isinstance(s, Index):
                exp = Index(np.unique(np.array(s_values, dtype=np.object_)))
                tm.assert_index_equal(s.unique(), exp)
            else:
                exp = np.unique(np.array(s_values, dtype=np.object_))
                tm.assert_numpy_array_equal(s.unique(), exp)

            assert s.nunique() == 4
            # don't sort, have to sort after the fact as not sorting is
            # platform-dep
            hist = s.value_counts(sort=False).sort_values()
            expected = Series([3, 1, 4, 2], index=list('acbd')).sort_values()
            tm.assert_series_equal(hist, expected)

            # sort ascending
            hist = s.value_counts(ascending=True)
            expected = Series([1, 2, 3, 4], index=list('cdab'))
            tm.assert_series_equal(hist, expected)

            # relative histogram.
            hist = s.value_counts(normalize=True)
            expected = Series([.4, .3, .2, .1], index=['b', 'a', 'd', 'c'])
            tm.assert_series_equal(hist, expected)
开发者ID:BobMcFry,项目名称:pandas,代码行数:31,代码来源:test_base.py


示例8: __init__

    def __init__(self, filename, diets = False, ctrlgrp = 99):
        self.rawdata = pd.read_csv(filename, sep=" ")
        self.rawdata['days'] = self.rawdata['days']/365.0 - 1.0 # scale days

        # select subgroups
        if diets == False:  # select all diet groups
            self.data = self.rawdata
        else:
            self.data = self.rawdata[np.in1d(self.rawdata['diet'], diets)]

        # set parameters
        self.unidays = np.unique(self.data['days'])
        self.unidiets = np.unique(self.data['diet'])
        self.ctrlidx = np.where(self.unidiets == ctrlgrp)[0][0]
        self.uniids = np.unique(self.data['id'])
        self.grp = self.unidiets.size # total number of diets
        self.ntot = self.uniids.size # total number of mouse
        self.grp_uniids = {}
        self.grp_ntot = {}
        self.grp_dtot = {}
        for g in self.unidiets:
            temp = self.data['id'][self.data['diet']==g]
            self.grp_uniids.update({g: np.unique(temp)})
            # number of total number of measurements in a group
            self.grp_dtot.update({g: temp.size})
            # number of unique ids in a group
            self.grp_ntot.update({g: self.grp_uniids[g].size})
        self.id_dtot = {}
        for i in self.uniids:
            temp = self.data['days'][self.data['id']==i]
            # number of measurements for each ids
            self.id_dtot.update({i: temp.size})
开发者ID:LeiG,项目名称:MouseWeights,代码行数:32,代码来源:main.py


示例9: fit

    def fit(self,X,y=None):
        """Fit a model: 

        Parameters
        ----------

        X : pandas dataframe or array-like
           training samples. If pandas dataframe can handle dict of feature in one column or cnvert a set of columns
        y : array like, required for array-like X and not used presently for pandas dataframe
           class labels

        Returns
        -------
        self: object


        """
        if isinstance(X,pd.DataFrame):
            df = X
            if not self.dict_feature is None:
                if not self.target_readable is None:
                    self.create_class_id_map(df,self.target,self.target_readable)
                (X,y) = self._load_from_dict(df)
                num_class = len(np.unique(y))
            else:
                (X,y,self.vectorizer) = self.convert_numpy(df)
                num_class = len(y.unique())
        else:
            check_X_y(X,y)
            num_class = len(np.unique(y))

        self.clf = xgb.XGBClassifier(**self.params)
        print self.clf.get_params(deep=True)
        self.clf.fit(X,y,verbose=True)
        return self
开发者ID:yangwx1402,项目名称:seldon-server,代码行数:35,代码来源:xgb.py


示例10: kmeans

def kmeans(xx, centroids, maxIters = 20, minclust=30, maxDiff = 2):

  # Cluster Assignment step
  ca = np.array([np.argmin([np.dot(x_i-y_k, x_i-y_k) for y_k in centroids]) for x_i in xx])
  # all clusters have at least minclust?
  (unique, counts) = np.unique(ca, return_counts=True)
  for cc in counts:
    if cc < minclust:
      return("error: too few", np.array(centroids), ca)
  # Move centroids step
  centroids = np.array([xx[ca == k].mean(axis = 0) for k in range(centroids.shape[0])])

  iter=1
  while (iter<maxIters):
      # Cluster Assignment step
      canew = np.array([np.argmin([np.dot(x_i-y_k, x_i-y_k) for y_k in centroids]) for x_i in xx])
      # all clusters have at least minclust?
      (unique, counts) = np.unique(canew, return_counts=True)
      for cc in counts:
        if cc < minclust:
          return("error: too few", np.array(centroids), canew)
      numdiff = sum(ca != canew)
      if numdiff < maxDiff:
        return("converged", np.array(centroids), canew)
      ca = canew
      # Move centroids step
      centroids = np.array([xx[ca == k].mean(axis = 0) for k in range(centroids.shape[0])])
      iter += 1

  return("error: not converged", np.array(centroids), ca)
开发者ID:mpsbpbi,项目名称:sequel-mixturemodel-code,代码行数:30,代码来源:kmeans.py


示例11: _get_obs_index_groups

	def _get_obs_index_groups(self):
		" Computes index groups for given observation scheme. "

		J = np.zeros((self._p, self.num_subpops), dtype=bool) 

		def any_observed(x):
			return x.size > 0

		for i in np.where(map(any_observed, self._sub_pops))[0]:
			J[self._sub_pops[i],i] = 1

		twoexp = np.power(2,np.arange(self.num_subpops))
		hsh = np.sum(J*twoexp,1)                     

		lbls = np.unique(hsh)

		idx_grp = []
		for i in range(lbls.size):
			idx_grp.append(np.where(hsh==lbls[i])[0])

		obs_idx = []
		for i in range(self.num_obstime):
			obs_idx.append([])
			for j in np.unique(hsh[np.where(J[:,self._obs_pops[i]]==1)]):
				obs_idx[i].append(np.where(lbls==j)[0][0])            

		return tuple(obs_idx), tuple(idx_grp)
开发者ID:mackelab,项目名称:pyLDS_dev,代码行数:27,代码来源:obs_scheme.py


示例12: evaluateSpeakerDiarization

def evaluateSpeakerDiarization(flags, flagsGT):

	minLength = min( flags.shape[0], flagsGT.shape[0] )
	flags = flags[0:minLength]
	flagsGT = flagsGT[0:minLength]

	uFlags = numpy.unique(flags)
	uFlagsGT = numpy.unique(flagsGT)	

	# compute contigency table:
	cMatrix = numpy.zeros(( uFlags.shape[0], uFlagsGT.shape[0] ))
	for i in range(minLength):
		cMatrix[ int(numpy.nonzero(uFlags==flags[i])[0]), int(numpy.nonzero(uFlagsGT==flagsGT[i])[0]) ] += 1.0

	Nc, Ns = cMatrix.shape;
	N_s = numpy.sum(cMatrix,axis=0);
	N_c = numpy.sum(cMatrix,axis=1);
	N   = numpy.sum(cMatrix);

	purityCluster = numpy.zeros( (Nc,) )
	puritySpeaker = numpy.zeros( (Ns,) )
	# compute cluster purity:
	for i in range(Nc):
		purityCluster[i] = numpy.max( (cMatrix[i,:]) )/ (N_c[i]);

	for j in range(Ns):
		puritySpeaker[j] = numpy.max( (cMatrix[:,j]) )/ (N_s[j]);

	purityClusterMean = numpy.sum(purityCluster*N_c) / N;
	puritySpeakerMean = numpy.sum(puritySpeaker*N_s) / N;
	
	return purityClusterMean, puritySpeakerMean
开发者ID:pacificIT,项目名称:pyAudioAnalysis,代码行数:32,代码来源:audioSegmentation.py


示例13: spatio_temporal_src_connectivity

def spatio_temporal_src_connectivity(src, n_times):
    """Compute connectivity for a source space activation over time

    Parameters
    ----------
    src : source space
        The source space.

    n_times : int
        Number of time instants

    Returns
    -------
    connectivity : sparse COO matrix
        The connectivity matrix describing the spatio-temporal
        graph structure. If N is the number of vertices in the
        source space, the N first nodes in the graph are the
        vertices are time 1, the nodes from 2 to 2N are the vertices
        during time 2, etc.

    """
    if src[0]['use_tris'] is None:
        raise Exception("The source space does not appear to be an ico "
                        "surface. Connectivity cannot be extracted from "
                        "non-ico source spaces.")
    lh_tris = np.searchsorted(np.unique(src[0]['use_tris']),
                              src[0]['use_tris'])
    rh_tris = np.searchsorted(np.unique(src[1]['use_tris']),
                              src[1]['use_tris'])
    tris = np.concatenate((lh_tris, rh_tris + np.max(lh_tris) + 1))
    return spatio_temporal_tris_connectivity(tris, n_times)
开发者ID:sudo-nim,项目名称:mne-python,代码行数:31,代码来源:source_estimate.py


示例14: check_and_set_idx

def check_and_set_idx(ids, idx, prefix):
    """ Reconciles passed-in IDs and indices and returns indices, as well as unique IDs
    in the order specified by the indices.  If only IDs supplied, returns the sort-arg
    as the index.  If only indices supplied, returns None for IDs.  If both supplied,
    checks that the correspondence is unique and returns unique IDs in the sort order of
    the associated index.
    :param np.ndarray ids: array of IDs
    :param np.ndarray[int] idx: array of indices
    :param str prefix: variable name (for error logging)
    :return: unique IDs and indices (passed in or derived from the IDs)
    :rtype: np.ndarray, np.ndarray
    """
    if ids is None and idx is None:
        raise ValueError('Both {}_ids and {}_idx cannot be None'.format(prefix, prefix))
    if ids is None:
        return None, np.asarray_chkfinite(idx)
    if idx is None:
        return np.unique(ids, return_inverse=True)
    else:
        ids = np.asarray(ids)
        idx = np.asarray_chkfinite(idx)
        if len(idx) != len(ids):
            raise ValueError('{}_ids ({}) and {}_idx ({}) must have the same length'.format(
                prefix, len(ids), prefix, len(idx)))
        uniq_idx, idx_sort_index = np.unique(idx, return_index=True)
        # make sure each unique index corresponds to a unique id
        if not all(len(set(ids[idx == i])) == 1 for i in uniq_idx):
            raise ValueError("Each index must correspond to a unique {}_id".format(prefix))
        return ids[idx_sort_index], idx
开发者ID:Guangzhan,项目名称:edm2016,代码行数:29,代码来源:utils.py


示例15: check_classifiers_classes

def check_classifiers_classes(name, Classifier, X, y, y_names):
    if name in ["LabelPropagation", "LabelSpreading"]:
        # TODO some complication with -1 label
        y_ = y
    else:
        y_ = y_names

    classes = np.unique(y_)
    # catch deprecation warnings
    with warnings.catch_warnings(record=True):
        classifier = Classifier()
    # fit
    try:
        classifier.fit(X, y_)
    except Exception as e:
        print(e)

    y_pred = classifier.predict(X)
    # training set performance
    assert_array_equal(np.unique(y_), np.unique(y_pred))
    accuracy = accuracy_score(y_, y_pred)
    assert_greater(accuracy, 0.78,
                   "accuracy %f of %s not greater than 0.78"
                   % (accuracy, name))
    #assert_array_equal(
        #clf.classes_, classes,
        #"Unexpected classes_ attribute for %r" % clf)
    if np.any(classifier.classes_ != classes):
        print("Unexpected classes_ attribute for %r: "
              "expected %s, got %s" %
              (classifier, classes, classifier.classes_))
开发者ID:DearMonster,项目名称:nb_sklearn,代码行数:31,代码来源:test_common.py


示例16: main

def main():
    '''Train tha model and evaluate performance'''

    '''Load the MNIST training data. Also flatten the images from 28X28 arrays to a single vector'''
    images, labels = amitgroup.io.mnist.load_mnist('training', path='./', asbytes=True)
    images = [image.ravel() for image in images]

    '''Find unique labels and which are the first images that correspnd to them'''
    indices = unique(labels, return_index=True)[1]

    '''Create the clustering engine. Use the unique images found above as centers'''
    clustering = Kmeans()
    clustering.train(data=images, centers=take(images, indices, axis=0), max_iterations=100)

    '''Load the testing data set and flatten the images'''
    test_images, test_labels = amitgroup.io.load_mnist('testing', path='./', asbytes=True)
    test_images = [image.ravel() for image in test_images]

    '''Assign the test data to clusters and evaluate the performance'''
    predictions = [clustering.cluster(image) for image in test_images]
    success = (predictions == test_labels)
    correct, counts = unique(success, return_counts=True)

    print('{} of the testing data set where put in the wrong cluster'.format(counts[0]))

    plot_images_separately([reshape(center, (28,28)) for center in clustering.centers])
开发者ID:BabisK,项目名称:M36104P,代码行数:26,代码来源:kmeans_on_mnist.py


示例17: mask_rowcols

def mask_rowcols(a, axis=None):
    """
    Mask whole rows and/or columns of a 2D array that contain
    masked values.  The masking behavior is selected with the
    `axis` parameter.

        - If axis is None, rows and columns are masked.
        - If axis is 0, only rows are masked.
        - If axis is 1 or -1, only columns are masked.

    Parameters
    ----------
    axis : int, optional
        Axis along which to perform the operation.
        If None, applies to a flattened version of the array.

    Returns
    -------
     a *pure* ndarray.

    """
    a = asarray(a)
    if a.ndim != 2:
        raise NotImplementedError, "compress2d works for 2D arrays only."
    m = getmask(a)
    # Nothing is masked: return a
    if m is nomask or not m.any():
        return a
    maskedval = m.nonzero()
    a._mask = a._mask.copy()
    if not axis:
        a[np.unique(maskedval[0])] = masked
    if axis in [None, 1, -1]:
        a[:, np.unique(maskedval[1])] = masked
    return a
开发者ID:zoccolan,项目名称:eyetracker,代码行数:35,代码来源:extras.py


示例18: test_volatility_communities

def test_volatility_communities():
    # Test volatility
    G = np.zeros([4, 4, 3])
    G[0, 1, [0, 2]] = 1
    G[2, 3, [0, 1]] = 1
    G[1, 2, [1, 2]] = 1
    G = G + G.transpose([1, 0, 2])
    communities = [0, 0, 1, 1]
    # global volatility
    v_bet = teneto.networkmeasures.volatility(
        G, calc='betweencommunities', communities=communities)
    v_within = teneto.networkmeasures.volatility(
        G, calc='withincommunities', communities=communities)
    v_communities = teneto.networkmeasures.volatility(
        G, calc='communities', communities=communities)
    if not len(v_bet) == G.shape[-1] - 1:
        raise AssertionError()
    if not len(v_within) == G.shape[-1] - 1:
        raise AssertionError()
    if not np.all(v_communities.shape == (
        len(np.unique(communities)), len(np.unique(communities)), G.shape[-1] - 1)):
        raise AssertionError()
    # Hardcode answer due to hamming distance and predefined matrix
    if not np.all(v_within == [0.5, 1]):
        raise AssertionError()
    if not np.all(v_bet == [0.25, 0]):
        raise AssertionError()
    if not np.all(v_communities[:, :, 0] == np.array([[1, 0.25], [0.25, 0]])):
        raise AssertionError()
    if not np.all(v_communities[:, :, 1] == np.array([[1, 0], [0, 1]])):
        raise AssertionError()
开发者ID:wiheto,项目名称:teneto,代码行数:31,代码来源:test_volatility.py


示例19: getWords

def getWords(imageloc,finalBoundingboxesFiltered):
	img=io.imread(imageloc)
	imgray=color.rgb2gray(img)
	horizontaldistances=[]
	verticaldistances=[]
	imgwidth=Image.open(imageloc).size[0]

	for i in range(0,len(finalBoundingboxesFiltered)):
		for j in range (i+1,len(finalBoundingboxesFiltered)):
			item1=finalBoundingboxesFiltered[i]
			item2=finalBoundingboxesFiltered[j]
			h=getDistHorizontal(item1,item2)
			v=getDistVertical(item1,item2)
			if h!=0:
				horizontaldistances.append(h)
			if v!=0:
				verticaldistances.append(v)
	global HORIZONTALTHRESHOLD
	global VERTICALTHRESHOLD

	#print horizontaldistances,verticaldistances
	HORIZONTALTHRESHOLD=sorted(np.unique(horizontaldistances))[2]+1
	VERTICALTHRESHOLD=sorted(np.unique(verticaldistances))[1]+1
	print "using horizontal and vertical thresholds",HORIZONTALTHRESHOLD,VERTICALTHRESHOLD
	nomerges=1
	while(nomerges):
		(finalBoundingboxesFiltered,nomerges)=mergeOnce(imgray,finalBoundingboxesFiltered,imgwidth)	

	finalBoundingboxes=finalBoundingboxesFiltered
	return finalBoundingboxes	
开发者ID:sagnik,项目名称:data-extraction-from-linegraphs,代码行数:30,代码来源:wordExtractionfromImagemymethod.py


示例20: test_ward_clustering

def test_ward_clustering():
    """
    Check that we obtain the correct number of clusters with Ward clustering.
    """
    rnd = np.random.RandomState(0)
    mask = np.ones([10, 10], dtype=np.bool)
    X = rnd.randn(100, 50)
    connectivity = grid_to_graph(*mask.shape)
    clustering = Ward(n_clusters=10, connectivity=connectivity)
    clustering.fit(X)
    # test caching
    clustering = Ward(n_clusters=10, connectivity=connectivity,
                      memory=mkdtemp())
    clustering.fit(X)
    labels = clustering.labels_
    assert_true(np.size(np.unique(labels)) == 10)
    # Turn caching off now
    clustering = Ward(n_clusters=10, connectivity=connectivity)
    # Check that we obtain the same solution with early-stopping of the
    # tree building
    clustering.compute_full_tree = False
    clustering.fit(X)
    np.testing.assert_array_equal(clustering.labels_, labels)
    clustering.connectivity = None
    clustering.fit(X)
    assert_true(np.size(np.unique(clustering.labels_)) == 10)
    # Check that we raise a TypeError on dense matrices
    clustering = Ward(n_clusters=10,
                      connectivity=connectivity.todense())
    assert_raises(TypeError, clustering.fit, X)
    clustering = Ward(n_clusters=10,
                      connectivity=sparse.lil_matrix(
                          connectivity.todense()[:10, :10]))
    assert_raises(ValueError, clustering.fit, X)
开发者ID:2011200799,项目名称:scikit-learn,代码行数:34,代码来源:test_hierarchical.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python numpy.unique1d函数代码示例发布时间:2022-05-27
下一篇:
Python numpy.union1d函数代码示例发布时间: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