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


Python numpy.vsplit函数代码示例

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


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

示例1: valid

def valid():
    rows = np.vsplit(puzzle, 9)
    cols = np.hsplit(puzzle, 9)
    grids = [grid for h in np.hsplit(puzzle, 3) for grid in np.vsplit(h, 3)]

    units = rows + cols + grids
    return all(np.max(np.bincount(unit[unit != 0])) == 1 for unit in units)
开发者ID:neingeist,项目名称:python-exercises,代码行数:7,代码来源:sudoku.py

示例2: fun_find_pairwise_distances

def fun_find_pairwise_distances(x, y):
    """
    A functional implementation of the same function
    """
    return np.array([[np.linalg.norm(x_elem - y_elem)
                      for y_elem in np.vsplit(y, y.shape[0])]
                     for x_elem in np.vsplit(x, x.shape[0])])
开发者ID:izmailovpavel,项目名称:Practicum,代码行数:7,代码来源:problem_7.py

示例3: cross_validation

def cross_validation(trndata, folds=3, **kwargs):
    """
        kwargs are parameters for the model
    """
    input = np.vsplit(trndata['input'], folds)
    target = np.vsplit(trndata['target'], folds)

    zipped = zip(input, target)

    accuracy_sum = 0
    for i in len(zipped):
        new_train = ClassificationDataSet(attributes, nb_classes=classes_number)
        new_test = ClassificationDataSet(attributes, nb_classes=classes_number)
        test_zipped = zipped[i]
        train_zipped = zipped[:i] + zipped[(i+1):]

        new_train.setField('input', np.vstack[train_zipped[0]])
        new_train.setField('target', np.vstack[train_zipped[1]])

        new_test.setField('input', test_zipped[0])
        new_test.setField('target', train_zipped[1])

        model = FNNClassifier()
        model.train(new_train, new_test, kwargs)
        out, targ = model.predict(new_test)
        accuracy_sum += accuracy(out, targ)

    return accuracy_sum / folds
开发者ID:sacherus,项目名称:pca-image,代码行数:28,代码来源:forest_main.py

示例4: ChangeSize

    def ChangeSize(self,n_nodes):
        self.masses.resize((1,n_nodes),refcheck=False)
        #self.masses=np.resize(self.masses,(1,n_nodes))
        #self.masses[0][-1] #bug in resize??
        self.initDisp.resize((1,n_nodes),refcheck=False)
        self.initVel.resize((1,n_nodes),refcheck=False)
        #self.initDisp=np.resize(self.initDisp,(1,n_nodes))
        #self.initVel=np.resize(self.initVel,(1,n_nodes))
        

        if n_nodes>self.n_nodes:
            #Take care of 2D array manipulation
            delta=n_nodes-self.n_nodes
            hor=np.zeros((self.n_nodes,delta))
            ver=np.zeros((delta,n_nodes))
            self.springs=np.vstack((np.hstack((self.springs,hor)),ver))
            self.dampers=np.vstack((np.hstack((self.dampers,hor)),ver))
            # Take care of displacement and forces list
            print self.n_nodes,n_nodes
            for i in range(0,n_nodes-self.n_nodes):
                #print i
                self.displacements.append(-1)
                self.forces.append(-1)
            #addArray=[0 for x in range(self.syst.n_nodes,n_nodes)]
        elif n_nodes<self.n_nodes:
            self.springs=np.hsplit(np.vsplit(self.springs,(n_nodes,n_nodes))[0],(n_nodes,n_nodes))[0]
            self.dampers=np.hsplit(np.vsplit(self.dampers,(n_nodes,n_nodes))[0],(n_nodes,n_nodes))[0]
            self.displacements=self.displacements[0:n_nodes]
            self.forces=self.forces[0:n_nodes]
        self.n_nodes=n_nodes
开发者ID:snexus,项目名称:ODDS,代码行数:30,代码来源:odds.py

示例5: fit

    def fit(self, X, y):

        if self.__unsupervised_thresh is not None:

            # user can pass in a negative to let us decide
            if self.__unsupervised_thresh <= 0:
                self.__unsupervised_thresh = 20

            qb = dipy.segment.clustering.QuickBundles(
                threshold=self.__unsupervised_thresh, metric=dipy.segment.metric.AveragePointwiseEuclideanMetric())
            clusters = qb.cluster(numpy.vsplit(numpy.reshape(X, (-1, 3)), X.shape[0]))
            cluster_labels = list()
            for cluster in clusters:
                current_labels, current_label_counts = numpy.unique(y[cluster.indices], return_counts=True)
                cluster_labels.append(current_labels[numpy.argmax(current_label_counts)])
            self.__centroids = map(lambda cl: cl.centroid, clusters)
            self.__centroid_labels = numpy.array(cluster_labels)

        else:

            unique_labels = numpy.unique(y)
            centroids = numpy.full((len(unique_labels), X.shape[1]), numpy.nan)
            for index_label, unique_label in enumerate(unique_labels):
                centroids[index_label] = numpy.mean(X[y == unique_label], axis=0)
            self.__centroids = numpy.vsplit(centroids.reshape((-1, 3)), centroids.shape[0])
            self.__centroid_labels = unique_labels
开发者ID:danrsc,项目名称:neuro_atlas,代码行数:26,代码来源:neuro_atlas_analysis.py

示例6: create_batches

    def create_batches(self):
        self.num_batches = self.tensor.size / (self.batch_size * self.seq_length)

        newline = self.vocab['\n']
        nextnew = np.where(self.tensor == newline)
        n_tunes = nextnew[0].size

        print "preparing chunks..."
        pos = 0
        n_tune = 0
        x_chunks = np.array([], dtype=int)
        y_chunks = np.array([], dtype=int)
        for nl in nextnew[0]:
            while (pos + self.seq_length < nl):
                x_chunks = np.append(x_chunks, self.tensor[pos : pos + self.seq_length])
                y_chunks = np.append(y_chunks, self.tensor[pos + 1 : pos + self.seq_length + 1])
                pos += 1
            n_tune += 1
            print "done tune ", n_tune, "/", n_tunes
            pos += self.seq_length

        print "reshaping to seq_length..."
        x_chunks = np.copy(np.reshape(x_chunks, (-1, self.seq_length)))
        y_chunks = np.copy(np.reshape(y_chunks, (-1, self.seq_length)))

        print "truncating to match batch_size"
        x, y = x_chunks.shape
        self.num_batches = x / self.batch_size
        print "%i batches" % self.num_batches
        x_chunks.resize((self.num_batches * self.batch_size, self.seq_length))
        y_chunks.resize((self.num_batches * self.batch_size, self.seq_length))

        self.x_batches = np.vsplit(x_chunks, self.num_batches)
        self.y_batches = np.vsplit(y_chunks, self.num_batches)
        print "batches ready!"
开发者ID:pierrebeauguitte,项目名称:char-rnn-tensorflow,代码行数:35,代码来源:utils.py

示例7: test_validation_curve_cv_splits_consistency

def test_validation_curve_cv_splits_consistency():
    n_samples = 100
    n_splits = 5
    X, y = make_classification(n_samples=100, random_state=0)

    scores1 = validation_curve(SVC(kernel='linear', random_state=0), X, y,
                               'C', [0.1, 0.1, 0.2, 0.2],
                               cv=OneTimeSplitter(n_splits=n_splits,
                                                  n_samples=n_samples))
    # The OneTimeSplitter is a non-re-entrant cv splitter. Unless, the
    # `split` is called for each parameter, the following should produce
    # identical results for param setting 1 and param setting 2 as both have
    # the same C value.
    assert_array_almost_equal(*np.vsplit(np.hstack(scores1)[(0, 2, 1, 3), :],
                                         2))

    scores2 = validation_curve(SVC(kernel='linear', random_state=0), X, y,
                               'C', [0.1, 0.1, 0.2, 0.2],
                               cv=KFold(n_splits=n_splits, shuffle=True))

    # For scores2, compare the 1st and 2nd parameter's scores
    # (Since the C value for 1st two param setting is 0.1, they must be
    # consistent unless the train test folds differ between the param settings)
    assert_array_almost_equal(*np.vsplit(np.hstack(scores2)[(0, 2, 1, 3), :],
                                         2))

    scores3 = validation_curve(SVC(kernel='linear', random_state=0), X, y,
                               'C', [0.1, 0.1, 0.2, 0.2],
                               cv=KFold(n_splits=n_splits))

    # OneTimeSplitter is basically unshuffled KFold(n_splits=5). Sanity check.
    assert_array_almost_equal(np.array(scores3), np.array(scores1))
开发者ID:RomainBrault,项目名称:scikit-learn,代码行数:32,代码来源:test_validation.py

示例8: fold_eta

    def fold_eta(self):
        crap, self.ybins = np.split(self.ybins, 2)

        negeta, poseta = np.vsplit(self.Z, 2)
        negeta = negeta[::-1]
        self.Z = (negeta + poseta)/2

        negeta, poseta = np.vsplit(self.err2, 2)
        negeta = negeta[::-1]
        self.err2 = (negeta + poseta)/4
开发者ID:slindal,项目名称:ana,代码行数:10,代码来源:pyh2.py

示例9: get_batches

def get_batches(X, Y, batch_size):
    '''
    Return a random data sample of size n from data X
    and their respective labels from Y.
    '''
    n_data, m_data = X.shape
    shuffled_inds = np.random.permutation(n_data)
    shuffled_data = X[shuffled_inds]
    shuffled_targ = Y[shuffled_inds]
    partitioned_data = np.vsplit(shuffled_data, n_data//batch_size)
    partitioned_targ = np.vsplit(shuffled_targ, n_data//batch_size)
    return partitioned_data, partitioned_targ
开发者ID:pkukulak,项目名称:PHL348_A3,代码行数:12,代码来源:load_data.py

示例10: kernelLDA

def kernelLDA(trainFile, validFile, labelsFile, gamma):

	trainData = np.loadtxt(open(trainFile))
	validationData = np.loadtxt(open(validFile))
	labels = np.loadtxt(open(labelsFile))

	print "Read training and validation data from files..."

	class1 = []
	class2 = []

	for i in range(len(labels)):
		if labels[i] == 1:
			class1.append(trainData[i])
		else:
			class2.append(trainData[i])

	class1 = np.vstack(tuple(class1))
	class2 = np.vstack(tuple(class2))

	data = np.concatenate((class1, class2))

	kernel_mat, kernelCentered_mat = getKernelMatrix(data, gamma)

	print "Kernel matrix obtained."

	K1 = np.vsplit(kernelCentered_mat, [class1.shape[0], data.shape[0]])[0]
	K2 = np.vsplit(kernelCentered_mat, [class1.shape[0], data.shape[0]])[1]

	mat_N1 = K1.T.dot( \
	 		(np.identity(K1.shape[0]) - (np.ones((K1.shape[0], K1.shape[0])) / K1.shape[0]))).dot( \
	 		K1)

	mat_N2 = K2.T.dot( \
	 		(np.identity(K2.shape[0]) - (np.ones((K2.shape[0], K2.shape[0])) / K2.shape[0]))).dot( \
	 		K2)

	N = mat_N1 + mat_N2

	M1 = np.average(K1, axis = 0)
	M2 = np.average(K2, axis = 0)

	#alpha = np.linalg.inv(N).dot(M2 - M1)
	alpha = (M2 - M1)

	getDimensionReducedData(alpha, kernelCentered_mat, 1, 'train', trainFile.split('_')[0])

	sq_distances_valid = cdist(data, validationData, 'sqeuclidean')
	kernel_mat_valid = np.exp(-1 * gamma * sq_distances_valid)

	getDimensionReducedData(alpha, kernel_mat_valid, 1, 'valid', trainFile.split('_')[0])

	print "Finished."
开发者ID:prameelakavya,项目名称:naive-bayes-and-dimensinality-reduction-techniques,代码行数:53,代码来源:kernelLDA.py

示例11: selectSubsample

def selectSubsample(matrixX, matrixY, splits):
    separateX = numpy.vsplit(matrixX, splits)
    separateY = numpy.vsplit(matrixY, splits)
    trainXFinal = []
    trainYFinal = []
    testXFinal = []
    testYFinal = []
    for i in range(len(separateX)):
        x_train, x_test, y_train, y_test = train_test_split(
            separateX[i], separateY[i], train_size=trainPercent, random_state=finalSeed)
        trainXFinal.append(x_train)
        trainYFinal.append(y_train)
        testXFinal.append(x_test)
        testYFinal.append(y_test)
    return [trainXFinal, trainYFinal, testXFinal, testYFinal]
开发者ID:noraw,项目名称:CyborgBugs,代码行数:15,代码来源:transformFeatures.py

示例12: predict_old

def predict_old(test):
    img = cv2.imread('digits.png')
    gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

    # now we split the image to 5000 cells, each 20*20 size
    cells = [np.hsplit(row, 100) for row in np.vsplit(gray,50)]

    # Make it into a Numpy array. It size will be (50,100,20,20)
    x = np.array(cells)

    # now we prepare train_data and test_data
    train = x[:,:50].reshape(-1,400).astype(np.float32)     #Gives a new shape to an array without changing its data.
    if test==None: test = x[:, 50:100].reshape(-1,400).astype(np.float32)
    # create labels for train and test data
    k = np.arange(10)

    train_labels = np.repeat(k,250)[:, np.newaxis]  # Repeat elements of an array.
    test_labels = train_labels.copy()

    #cv2.KNearest.find_nearest(samples, k[, results[, neighborResponses[, dists]]]) → retval, results, neighborResponses, dists
    ret,result,neighbours,dist = knn.findNearest(test.reshape(-1,400).astype(np.float32),k=5)
    print '2-----:',result


    # Now we check the accuracy of classification
    # For that, compare the result with test_labels and check which are wrong
    matches = result==test_labels
    correct = np.count_nonzero(matches) # Counts the number of non-zero values in the array a.

    accuracy = correct*100.0/result.size
    print 'accuracy:',accuracy

    np.savez('knn_data.npz',train=train,train_labels=train_labels)
开发者ID:JamesPei,项目名称:PythonProjects,代码行数:33,代码来源:knn.py

示例13: evaluate_local_remainder_at

    def evaluate_local_remainder_at(self, grid, position, diagonal_component=None, entry=None):
        r"""Numerically evaluate the non-quadratic remainder :math:`W(x)` of the quadratic
        approximation :math:`U(x)` of the potential's eigenvalue :math:`\lambda(x)` at the
        given nodes :math:`\Gamma`.

        :param grid: The grid nodes :math:`\Gamma` the remainder :math:`W` gets evaluated at.
        :param position: The point :math:`q \in \mathbb{R}^D` where the Taylor series is computed.
        :param diagonal_component: Dummy parameter that has no effect here.
        :keyword entry: Dummy parameter that has no effect here.
        :return: A list with a single entry consisting of an ``ndarray`` containing the
                 values of :math:`W(\Gamma)`. The array is of shape :math:`(1,|\Gamma|)`.
        """
        grid = self._grid_wrap(grid)
        position = numpy.atleast_2d(position)

        # Evaluate the remainder at the given nodes
        args = grid.get_nodes(split=True) + numpy.vsplit(position, position.shape[0])
        values = self._remainder_n[0](*args)

        # Test for potential being constant
        if numpy.atleast_1d(values).shape == (1,):
            values = values * numpy.ones(grid.get_number_nodes(), dtype=numpy.complexfloating)

        # Put the result in correct shape (1, #gridnodes)
        N = grid.get_number_nodes(overall=True)
        result = [ values.reshape((1,N)) ]

        # TODO: Consider unpacking single ndarray iff entry != None
        if entry is not None:
            result = result[0]

        return result
开发者ID:GaZ3ll3,项目名称:WaveBlocksND,代码行数:32,代码来源:MatrixPotential1S.py

示例14: R_z

def R_z(x, y, z, alpha=0):
    """
    Rotation matrix for rotation about the z axis

    Parameters
    ----------
    x : `np.ndarray` with dims (1, N)
    y : `np.ndarray` with dims (1, N)
    z : `np.ndarray` with dims (1, N)
    alpha : float
        angle [radians] to rotate about the `z` axis counterclockwise

    Returns
    -------
    x2 : `np.ndarray` with dims (1, N)
        Rotated x positions
    y2 : `np.ndarray` with dims (1, N)
        Rotated y positions
    z2 : `np.ndarray` with dims (1, N)
        Rotated z positions
    """
    original_shape = x.shape
    xyz = np.vstack([x.ravel(), y.ravel(), z.ravel()])
    r_z = np.array([[np.cos(alpha), np.sin(alpha), 0],
                    [-np.sin(alpha), np.cos(alpha), 0],
                    [0, 0, 1]])
    new_xyz = np.dot(r_z, xyz)
    x2, y2, z2 = np.vsplit(new_xyz, 3)
    x2.resize(original_shape)
    y2.resize(original_shape)
    z2.resize(original_shape)
    return x2, y2, z2
开发者ID:bmorris3,项目名称:friedrich,代码行数:32,代码来源:orientation.py

示例15: process_mirror

 def process_mirror(cls, img, mode):
     if mode == 'Vertical':
         org = numpy.asarray(img)
         flip = numpy.fliplr(org)
         data1 = numpy.hsplit(org, 2)
         data2 = numpy.hsplit(flip, 2)
         data = numpy.hstack((data1[0], data2[1]))
         img = Image.fromarray(data)
     elif mode == 'Horizontal':
         org = numpy.asarray(img)
         flip = numpy.flipud(org)
         data1 = numpy.vsplit(org, 2)
         data2 = numpy.vsplit(flip, 2)
         data = numpy.vstack((data1[0], data2[1]))
         img = Image.fromarray(data)
     return img
开发者ID:jfhu,项目名称:kamera,代码行数:16,代码来源:other.py


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