Home | Trees | Indices | Help |
---|
|
Operations on numpy arrays not present in the standard package.
|
|||
Normal arrays | |||
---|---|---|---|
numpy array(, numpy array) |
|
||
numpy array |
|
||
(index,index) |
|
||
(index,index) |
|
||
|
|||
float |
|
||
|
|||
|
|||
Record arrays | |||
numpy record array |
|
||
numpy record array |
|
||
numpy record array |
|
||
|
|||
Line intersections | |||
|
|
Distil unique rows/cols from an array
Example with rows: >>> c = np.sort(np.random.normal(size=(3,5)),axis=0) >>> d = np.r_[c,c,c] >>> du = np.sort(unique_arr(d,axis=0),axis=0) >>> np.all(du==c) True Example with columns: >>> c = np.sort(np.random.normal(size=(3,5)),axis=1) >>> d = np.hstack([c,c]) >>> du = np.sort(unique_arr(d,axis=1),axis=1) >>> np.all(du==c) True
|
Sort an array along several axes >>> a = np.array([[ 0., 1.], [ 1., 1.], [ 1., 0.], [ 0., 0.], [ 0., 3.], [ 1., 0.], [ 1., 3.], [ 1., 2.], [ 1., 3.], [ 0., 4.]]) >>> sort_order(a,[0,1]) array([[ 0., 0.], [ 0., 1.], [ 0., 3.], [ 0., 4.], [ 1., 0.], [ 1., 0.], [ 1., 1.], [ 1., 2.], [ 1., 3.], [ 1., 3.]])
|
Calculate the argmax of a 2D array. Example usage: >>> output = np.zeros(100) >>> for i in xrange(100): ... a = np.random.normal(size=(5,6)) ... x,y = argmax2D(a) ... output[i] = (a[x,y] == a.max()) >>> sum(output) 100.0
|
Calculate the argmin of a 2D array. Example usage: >>> output = np.zeros(100) >>> for i in xrange(100): ... a = np.random.normal(size=(5,6)) ... x,y = argmin2D(a) ... output[i] = (a[x,y] == a.min()) >>> sum(output) 100.0
|
Return closest-match indices from b in a. Example usage: >>> a = np.random.uniform(size=10) >>> b = a[np.array(np.random.uniform(size=3)*10,int)] >>> ind = match_arrays(a,b) >>> all(a[ind] == b) True |
Calculates the weighted (sample) standard deviation of a list of numbers.
|
3 point Lagrangian differentiation. Returns z = dy/dx Example usage: >>> X = np.array([ 0.1, 0.3, 0.4, 0.7, 0.9]) >>> Y = np.array([ 1.2, 2.3, 3.2, 4.4, 6.6]) >>> deriv(X,Y) array([ 3.16666667, 7.83333333, 7.75 , 8.2 , 13.8 ]) |
Generate random points in a non-convex continuous rectangular grid. This routine will subdivide the grid in smaller cubicles and then
populate those with a number of points proportional to the relative size
of the cubicle. Because of this, Warning: This function requiresevery square to be populated by at least one point. If this is not the case, it will be forced that every square has a point. >>> xs = np.array([1,2,0,1,2,3,0,1,2,3,1,2.]) >>> ys = np.array([4,4,3,3,3,3,2,2,2,2,1,1.]) >>> gridpoints = np.column_stack([xs,ys]) >>> sample = random_rectangular_grid(gridpoints,10000) >>> p = pl.figure() >>> p = pl.plot(xs,ys,'ro') >>> p = pl.plot(sample[:,0],sample[:,1],'ko',ms=2) ]include figure]]ivs_aux_numpy_ext_grid.png] Gridpoints should be Ngridpoints x Ncols |
Convert an array to a record array. dtype = [('name1',int),('name2',float)] >>> x = np.array([[1,1],[2,2]]) >>> y = recarr(x,[('ones',int),('twos',int)]) >>> print y['ones'] [1 1]
|
Add rows to a record array >>> x = np.array([[1,1],[2,2]]) >>> y = recarr(x,[('ones',int),('twos',int)]) >>> z = recarr_addrows(y,[[1,2]]) >>> print z['ones'] [1 1 1]
|
Add columns to a record array >>> x = np.array([[1,1],[2,2]]) >>> y = recarr(x,[('ones',int),('twos',int)]) >>> z = recarr_addcols(y,[[3,3],[4,4]],[('threes',int),('fours',int)]) >>> print z['fours'] [4 4]
|
Find intersection of two 2D lines. Example usage: >>> pcoeff1 = [1,2,-2.] >>> pcoeff2 = [-2.12,2.45,3.7321] >>> x = np.linspace(-3,3,7) >>> A = np.column_stack([x,np.polyval(pcoeff1,x)]) >>> B = np.column_stack([x,np.polyval(pcoeff2,x)]) We find two intersections: >>> xs,ys = find_intersections(A,B) >>> print xs,ys [-1.22039755 1.34367003] [-2.77960245 2.71835017] >>> p = pl.figure() >>> p = pl.plot(x,A[:,1],'bo-') >>> p = pl.plot(x,B[:,1],'go-') >>> p = pl.plot(xs,ys,'rs',ms=5) Returns empty arrays when there are no intersections. ]include figure]]ivs_aux_numpy_ext_intersect.png] |
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Fri Mar 30 10:45:18 2018 | http://epydoc.sourceforge.net |