8.3 array -- A collection of numerical array utilities.

These are general utility functions that depend only on the numpy array model. All pyformex modules needing numpy should import everything from this module.

niceLogSize( f)
Return the smallest integer e such that 10**e > abs(f).

niceNumber( f,approx=floor)
Return a nice number close to but not smaller than f.

sind( arg)
Return the sin of an angle in degrees.

cosd( arg)
Return the cos of an angle in degrees.

tand( arg)
Return the tan of an angle in degrees.

dotpr( A,B,axis=-1)
Return the dot product of vectors of A and B in the direction of axis.

The default axis is the last.

length( A,axis=-1)
Returns the length of the vectors of A in the direction of axis.

The default axis is the last.

normalize( A,axis=-1)
Normalize the vectors of A in the direction of axis.

The default axis is the last.

projection( A,B,axis=-1)
Return the (signed) length of the projection of vector of A on B.

The default axis is the last.

norm( v,n=2)
Return a norm of the vector v.

Default is the quadratic norm (vector length) n == 1 returns the sum n <= 0 returns the max absolute value

inside( p,mi,ma)
Return true if point p is inside bbox defined by points mi and ma

isClose( values,target,rtol=1.e-5,atol=1.e-8)
Returns an array flagging the elements close to target.

values is a float array, target is a float value. values and target should be broadcastable to the same shape.

The return value is a boolean array with shape of values flagging where the values are close to target. Two values a and b are considered close if | a - b | < atol + rtol * | b |

origin( )
Return a point with coordinates [0.,0.,0.].

unitVector( axis)
Return a unit vector in the direction of a global axis (0,1,2).

Use normalize() to get a unit vector in a general direction.

rotationMatrix( angle,axis=None)
Return a rotation matrix over angle, optionally around axis.

The angle is specified in degrees. If axis==None (default), a 2x2 rotation matrix is returned. Else, axis should specifying the rotation axis in a 3D world. It is either one of 0,1,2, specifying a global axis, or a vector with 3 components specifying an axis through the origin. In either case a 3x3 rotation matrix is returned. Note that: rotationMatrix(angle,[1,0,0]) == rotationMatrix(angle,0) rotationMatrix(angle,[0,1,0]) == rotationMatrix(angle,1) rotationMatrix(angle,[0,0,1]) == rotationMatrix(angle,2) but the latter functions calls are more efficient. The result is returned as an array.

rotMatrix( v,n=3)
Create a rotation matrix that rotates axis 0 to the given vector.

Return either a 3x3(default) or 4x4(if n==4) rotation matrix.

growAxis( a,size,axis=-1,fill=0)
Grow a single array axis to the given size and fill with given value.

reverseAxis( a,axis=-1)
Reverse the elements along axis.

checkArray( a,shape=None,kind=None,allow=None)
Check that an array a has the correct shape and type.

The input a is anything that can e converted into a numpy array. Either shape and or kind can be specified. The dimensions where shape contains a -1 value are not checked. The number of dimensions should match, though. If kind does not match, but is included in allow, conversion to the requested type is attempted. Returns the array if valid. Else, an error is raised.

checkArray1D( a,size=None,kind=None,allow=None)
Check that an array a has the correct size and type.

Either size and or kind can be specified. If kind does not match, but is included in allow, conversion to the requested type is attempted. Returns the array if valid. Else, an error is raised.

checkUniqueNumbers( nrs,nmin=0,nmax=None,error=None)
Check that an array contains a set of uniqe integers in range.

nrs is an integer array with any shape. All integers should be unique and in the range(nmin,nmax). Beware: this means that nmin <= i < nmax ! Default nmax is unlimited. Set nmin to None to error is the value to return if the tests are not passed. By default, a ValueError is raised. On success, None is returned