Python/numpy Big Data programming experience 1. Edge Processing Edge save data, do not finish the disposable save. Otherwise the program ran for hours or even days after the hang, there is nothing. Even if some of the results are not practical, you can analyze the problem of the program flow or the characteristics of the data. 2. Release large chunks of memory with Del in time.
] # 1 1 1b[0][0] = 5print a[0][0], b[0][0], c[0][0] # 5 5 12) Use ': ' To access all data of a given dimensionA = Np.arange. Reshape (4, 5)print#取出 the 2nd to 4th element of each row of aArray stitchingA =np.array ([Np.array] ([4,5,6#] [1, 2, 3, 4, 5, 6]#[[1, 2, 3], # [4, 5, 6]Two Matrix objectsCreate a matrixThe matrix is two-dimensional, and the array can be any positive integer dimensionA = Np.arange (5#[[0, 1,
Usage of the numpy. apply_along_axis () function in Python,
Numpy.Apply_along_axis(Func,Axis,Arr,* Args,** Kwargs):
Required parameters: func, axis, and arr. Among them, func is a custom function, and arr in the function func (arr) is an array. The main function of the function is to transform every element in the logarithm group to get the target result.
Axis in
this had nothing to do with the Where () function of half a dimeresult = 1* (Cond1 -cond2) +2* (Cond2 -cond1) +3* (-(Cond1 |Cond2)) (I didn't think I could say that.)Print(Result)View CodeThe second way to usewhere (conditions)is equivalent to the subscript of the arrayx = Np.arange (+)print(X[np.where (x>5)))# output: (Array ([6, 7, 8, 9, ten, One, (), Dtype=int64),)= Np.arange (+). Reshape ( -1,4)print( Np.where (x>5))#(
Vectorization refers to using an array expression instead of a loop to manipulate each element in the array.The general functions provided by NumPy (both Ufunc functions) are functions that perform element-level operations on data in Ndarray. For example, the square function computes the square of each element, and the rint function rounds each element:There are also some functions that accept 2 parameters,
(200)>>a*a-25536 %int16 Not enough, calculate 200*200 overflowaccessing arrays>>a = Np.array () Array ([012345 6 7 8 9 ])>>a[5] % use integer as subscript to get an element in an array>>a[3:5]% do subscript with slices, get part of the array, including a[3] not including a[5]>>a[:5] % starting from 0 to A[4], excluding a[5]>>A[:-1]% T
expectation: {:. 3f}'. Format (stock_mean))Print('Stock 0 std Amplitude standard deviation: {:. 3f}'. Format (STOCK_STD))#draw a histogram of stock 0Plt.hist (Stock_day_change[0], bins=50, normed=True)#Linspace Generating data from the maximum value of stock 0 min .Fit_linspace =Np.linspace (Stock_day_change[0].min (), Stock_day_change[0].max ())#probability density functions (pdf,probability density function)#describe the curve by mean, variance, and use scipy.stats.norm.pdf to generate a fit
1. Definition and description of functions function format tile (a,reps)Both A and reps are array_like.A has many types, almost all of which can be: array, list, tuple, dict, matrix, and basic data type int, string, float, and bool type.There are also many types of reps, which can be tuple,list, dict, array, int, bool. But it cannot be a float, string, matrix type.2. Example of function operation>>> TileAr
In the process of learning KNN classification algorithm using the tile function, there are many do not understand, recorded the use of this function.Function prototype: Numpy.tile (a,reps) #简单理解是此函数将A进行重复输出Where a and reps are parameters of array_like, a can be: Array,list,tuple,dict,matrix and basic data type int,string,float and bool type, reps type can be tuple,list , Dict,array,int,bool, but cannot be a
matrix composed of sub-graphs of the number of rows, such as 6 sub-graphs, arranged into 3 rows 2 columns, that is subplot (3,2,x). The last number means to draw the first X chart. Usage in the job:#visualize some examples from the dataset.#We Show a few examples of training images from each class.classes = ['plane','Car','Bird','Cat','Deer','Dog','Frog','Horse',' Ship','Truck']#Category ListNum_classes = Len (classes)#Number of categoriesSamples_per_class = 7#number of samples per category for
Numpy.eye (N, M=none, k=0, dtype=Generate diagonal matrix columns n rows m write one representing the number of rows equals the number of columns K represents an offset positive upward offset, negative number downward offsetsuch as Numpy.eye (3,k=1,dtyle=int)0 1 00 0 10 0 0Numpy.shape (a)A is an array, which returns the size of several dimensions and the number of elements per dimensionNumpy.shape ([[1, 2]])(1, 2) 1-dimensional 2 elements per dimensio
1.np.logspace (start,stop,num): a function representation means that geometric series num is generated between (Start,stop)eg as npprint np.logspace (1,4,4)The result is: [10. 100.1000. 10000.]2. Np.fromstring (' admin ', dtype=np.int8): The function is to replace the string with the corresponding ASCII value as npprint np.fromstring ('admin', dtype= np.int8)The result is: [97 100 109 105 110]3. Customize your own data type:Import NumPy as NPStudent =
Keepdims is mainly used to maintain the two-dimensional properties of matricesImport= Np.array ([[1,2],[3,4]])# is added by line and retains the second dimension of print(Np.sum (A, Axis=1, keepdims=True)# Add by line, do not maintain the second dimension print(Np.sum (A, Axis=1))OutputArray ([[3], [7]]) array ([3, 7])--------------------------------------------------------------Reprinted from: http://blog.csdn.net/u012560212/article/details/7839383
There are many ways to merge numpy arrays in Python, such as-Np.append ()-Np.concatenate ()-Np.stack ()-Np.hstack ()-Np.vstack ()-Np.dstack ()One of the most ubiquitous is the first and the second. The first readability is good, more flexible, but the memory is big. The second one does not have a large memory footprint problem. Method A--append
Parameters
Introduction
Arr
Python image grayscale conversion and Image array operations, python Image Grayscale Array
Using python and numpy to complete a series of basic image processing by directly operating the Image
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.