#import int Main (int argc, const Char * argv[]) { @autoreleasepool { // variable array inheritance immutable variable group //1. Create A set number of elements to create nsmutablearray *mutarr=[nsmutablearray arraywithcapacity:7]; //2. add an element to an array nsarray *arr=@[@ "MON",@ "TUE",@ "WED",@ "THU",@ "FRI", @ "SAT",@ "SUN"]; nsmutablearray *mutarray=[nsmutablearray arraywitharray: arr]; [Mutarray addobject:@ "EIG
#import int main (int argc, const char * argv[]) {@autoreleasepool {Variable groups inherit immutable groups1. Create a set number of elementsNsmutablearray *mutarr=[nsmutablearray Arraywithcapacity:7];2. Add an element to the arrayNsarray *[email protected][@ "MON", @ "TUE", @ "WED", @ "THU", @ "FRI", @ "SAT", @ "SUN"];Nsmutablearray *mutarray=[nsmutablearray Arraywitharray:arr];[Mutarray addobject:@ "EIG"];3. Insert the element according to the spec
The Python operation can find the pixel point in an image. For example, a white pixel with black pixels will be found. import cv2.cv as cv # load imagefilename = ".. /Video/cat.jpg "image = cv. loadImage (filename) # create one windowwin_name = "test" cv. namedWindow (win_name) win2_name = "test2" cv. namedWindow (win2_name) cv. showImage (win2_name, image) # set created imagesize = cv. getSize (image) # (100,100) depth = 8 channels = 1 # gray operategrey = cv. createImage (size, depth, channels
-meanvals3) find out the covariance matrix of the Matrix after averaging>>> Covmat=np.cov (meanremove, rowvar=0)4) the eigenvalues and eigenvectors of the covariance matrix are obtained, and the Eig function in the NumPy library is Used.>>> Eigvals,eigvects=np.linalg.eig (np.mat (covmat))>>> eigvalsArray ([1.20374494e+01, 3.44539806e+00, 1.01715252e+00,-1.59662646e-16, 1.21625562e-16])>>> eigvectsMatrix ([[[0.20502268, 0.21893499,-0.80686681, 0.450186
function [V,s,e]=princa (x) [M,n]=size (x); The% calculates the row m and column n% of the matrix-------------the first step: the normalized matrix-----------------%mv=mean (X); % calculates the mean value of each variable st=std (X); % calculates the standard deviation of each variable x= (X-repmat (mv,m,1))./repmat (st,m,1); % normalized matrix x-------------Second step: Calculate the correlation coefficient matrix-----------------percent r1=x ' *x/(m-1); % method One: Covariance matrix calcul
The next problem is that when the model is symmetric, the result is expected, but when the model is asymmetrical, the result is wrong, as follows:Input: Vertex: 233Output:What the hell is this? , Where's my horse!!!There seems to be a logical error.Note that the debug information for the C + + output is as follows:The error message is: Input to EIG must not contain NaN, then a bunch of hot hot ...There is also a hint: Matrix is close to singular or ba
product of all elements
Methods for arrays of Boolean types#True直接当1计算In [24]: (arr2dSort
Np.sort () This will copy a copy.
Arr2d.sort () is the operation on the source data
5. Input and output for array filesTo save an array to disk in binary form
Np.save ()
Np.load ()
accessing text files
Np.loadtext ()
Np.savetext ()
6. Linear algebra is not found when the Numpy.linalg
Note: Transpose arr. T
Np.dot (ARR1,ARR2) The produc
(X)
print (pca.explained_ Variance_ratio_)
Test and test with a dataset of your own makingThe program extracts a characteristic value to reduce the dimensionality of two-dimensional data
Using PCA algorithm to reduce dimension of testSet.txt data set
Import NumPy as NP import Matplotlib.pyplot as Plt def loaddataset (filename, delim= ' \ t '): FR = open (filename) S
Tringarr = [Line.strip (). Split (Delim) for line in Fr.readlines ()] Datarr = [Map (float, line) for line in Stringarr] Ret
converted to C + + code, and the command line parameters are as follows:Generate C File: Mcc–t–l C x.mGenerate C + + files: mcc–t–l Cpp x.mGenerate dynamic link library functions: mcc–t–w lib:y–t link.lib x.m (Y for generated link file name)4. To import a link library:
#pragma comment (lib, "libmatlb.lib") #pragma comment (lib, "libmx.lib") #pragma comment (lib, "libmatpm.lib") // c++ maths library
5. The reference code is as follows:
double d[] = { 1, 2, 3, 4 }; mwArray A(2, 2, d); mwArray
(i,i)) * sqrt (d (j,j)))
;
End end% calculates eigenvalue eigenvectors [eigvectors,eigvalues] = Eig (L);
% selected before K maximum eigenvalue [eigvalues, Ind] = sort (diag (eigvalues), ' descend ');
Neigvec =eigvectors (:, Ind (1:K));
% constructs a normalized matrix U from the obtained eigenvector U=zeros (size (neigvec,1), k);
For I=1:size (neigvec,1) n = sqrt (sum (Neigvec (i,:). ^2)); U (i,:) = Neigvec (i,:).
N
End End Functio
)B =-0.0971-0.0178 0.06361.3591 1.5820-1.52660.0149-0.0178 0.06361.1351 1.0487-0.8905-0.0971-0.0178 0.0636-0.0971-0.0178 0.0636-0.9932-0.8177-0.8905-0.9932-0.8177 1.0178-1.6653-1.8842 1.9719-1.2173-1.3509 1.65392.0312 1.8486-1.52660.6870 0.5155-0.2544-0.0971-0.0178 0.06360.0149-0.0178 0.06360.0149-0.0178 0.0636Calculating the coefficients of the principal components and their respective variances are done by finding the Eigenfuncti ONS of the sample covariance matrix:>> [V D] =
\ foreigners \ Desktop \ orl \ s', num2str (I ), '\', num2str(j),'.bmp '); % imshow (a); B = a (* 92); % B is the row vector 1 × n, where n = 10304, the extraction sequence is to first run the column, that is, from top to bottom, from left to right B = double (B); allsamples = [allsamples; B]; % allsamples is an M * n matrix, each row of data in allsamples represents an image, where M = 200 endendsamplem EAN = mean (allsamples); % average image, 1 × Nfor I = xmean (I, :) = allsamples (I, :)-sam
ascending order:-sort (-y) or filplr (sort (r ))
Find: locate the position (not the element value) of the vector matrix element that meets the conditions or expressions specified by the user ). Y = [-1 2-3 4]. S = Y [find (Y Ones: One = ones (R, c ). Create a (RXC) matrix with 1 elements.
Zeros: ZER = zeros (R, c ). Create a (RXC) matrix with zero elements.
Magic: Magic (n ). Generates a special matrix, that is, the sum of elements in any row or column in the matrix, and the sum of elements on
going on here?Well, first of all, (i + (i >> 4)) 0x0F0F0F0F does exactly the same as the previous line, except it adds the adjacent four-bit Bitcou NTS together to give the bitcounts of each eight-bit block (i.e. byte) of the input. (Here, unlike to the previous line, we can get away with moving the outside the addition, since we know that the Eig Ht-bit Bitcount can never exceed 8, and therefore would fit inside four bits without overflowing.)Now
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.