Universal Functions (ufunc)
A universal function (or nlcpy.ufunc
for short) is a function that operates on ndarrays in an elementbyelement fashion, supporting array broadcasting, type casting, and several other standard features. That is, a ufunc is a "vectorized" wrapper for a function that takes a fixed number of specific inputs and produces a fixed number of specific outputs.
As with NumPy, Broadcasting rules are applied to input arrays of the universal functions of NLCPy.
Broadcasting
Each universal function takes array inputs and produces array outputs by performing the core function elementwise on the inputs (where an element is generally a scalar, but can be a vector or higherorder subarray for generalized ufuncs). Standard broadcasting rules are applied so that inputs not sharing exactly the same shapes can still be usefully operated on. Broadcasting can be understood by four rules:
All input arrays with ndim smaller than the input array of largest ndim, have 1's prepended to their shapes.
The size in each dimension of the output shape is the maximum of all the input sizes in that dimension.
An input can be used in the calculation if its size in a particular dimension either matches the output size in that dimension, or has value exactly 1.
If an input has a dimension size of 1 in its shape, the first data entry in that dimension will be used for all calculations along that dimension. In other words, the stepping machinery of the ufunc will simply not step along that dimension (the stride will be 0 for that dimension).
Examples
If a.shape is (5,1), b.shape is (1,6), c.shape is (6,) and d.shape is () so that d is a scalar, then a, b, c, and d are all broadcastable to dimension (5,6); and
a acts like a (5,6) array where a[:,0] is broadcast to the other columns,
b acts like a (5,6) array where b[0,:] is broadcast to the other rows,
c acts like a (1,6) array and therefore like a (5,6) array where c[:] is broadcast to every row, and finally,
d acts like a (5,6) array where the single value is repeated.
Available Ufuncs
The following tables show Universal functions(ufuncs) provided by NLCPy.
Math Operations
Computes the elementwise addition of the inputs. 

Computes the elementwise subtraction of the inputs. 

Computes the elementwise multiplication of the inputs. 

Matrix product of two arrays. 

Computes the elementwise division of the inputs. 

Computes the elementwise natural logarithm of . 

Computes the elementwise base2 logarithm of . 

Computes the elementwise division of the inputs. 

Computes the elementwise floor division of the inputs. 

Computes numerical negative, elementwise. 

Computes numerical positive, elementwise. 

Computes the elementwise exponentiation of the inputs. 

Computes the elementwise remainder of division. 

Computes the elementwise remainder of division. 

Computes the elementwise remainder of division. 

Computes the elementwise absolute value. 

Computes the elementwise absolute value. 

Computes the elementwise nearest integer. 

Computes Heaviside step function. 

Returns the elementwise complex conjugate. 

Returns the elementwise complex conjugate. 

Computes the exponential of all elements in the input array. 

Computes 2**x for all elements in the array. 

Computes the elementwise natural logarithm of x. 

Computes the elementwise base2 logarithm of x. 

Computes the elementwise base10 logarithm of x. 

Computes the elementwise natural logarithm of 1 + x. 

Computes exp(x)  1 for all elements in the array. 

Computes the elementwise squareroot of the input. 

Computes the elementwise square of the input. 

Computes the elementwise cubicroot of the input. 

Computes the elementwise reciprocal of the input. 
Trigonometric Functions
Computes the elementwise sine. 

Computes the elementwise cosine. 

Computes the elementwise tangent. 

Computes the elementwise inverse sine. 

Computes the elementwise inverse cosine. 

Computes the elementwise inverse tangent. 

Computes the elementwise inverse tangent of x1/x2 choosing the quadrant correctly. 

Computes the "legs" of a right triangle. 

Computes the elementwise hyperbolic sine. 

Computes the elementwise hyperbolic cosine. 

Computes the elementwise hyperbolic tangent. 

Computes the elementwise inverse hyperbolic sine. 

Computes the elementwise inverse hyperbolic cosine. 

Computes the elementwise inverse hyperbolic tangent. 

Converts angles from radians to degrees. 

Converts angles from degrees to radians. 

Converts angles from degrees to radians. 

Converts angles from radians to degrees. 
BitTwiddling Functions
Computes the bitwise AND of two arrays elementwise. 

Computes the bitwise OR of two arrays elementwise. 

Computes the bitwise XOR of two arrays elementwise. 

Computes the bitwise NOT elementwise. 

Shifts bits of an integer to the left, elementwise. 

Shifts bits of an integer to the right, elementwise. 
Comparison Functions
Returns (x1 > x2), elementwise. 

Returns (x1 >= x2), elementwise. 

Returns (x1 < x2), elementwise. 

Returns (x1 <= x2), elementwise. 

Returns (x1 != x2), elementwise. 

Returns (x1 == x2), elementwise. 

Computes the logical AND of two arrays elementwise. 

Computes the logical OR of two arrays elementwise. 

Computes the logical XOR of two arrays elementwise. 

Computes the logical NOT of the input array elementwise. 

Computes the elementwise maximum of the inputs. 

Computes the elementwise minimum of the inputs. 

Computes the elementwise maximum of the inputs. 

Computes the elementwise minimum of the inputs. 
Floating Point Functions
Tests whether input elements are neither inf nor nan, or not. 

Tests whether input elements are inf, or not. 

Tests whether input elements are nan, or not. 

Returns True where signbit is set (less than zero), elementwise. 

Changes the sign of x1 to that of x2, elementwise. 

Returns the elementwise indication of the sign of a number. 

Returns the next floatingpoint value after x1 towards x2, elementwise. 

Returns the distance between x and the nearest adjacent number, elementwise. 

Returns , elementwise. 

Returns the floor of the input, elementwise. 

Returns the ceiling of the input, elementwise. 

Returns the truncated value of the input, elementwise. 
Methods
In NLCPy, ufuncs are instances of the nlcpy.ufunc
class.
nlcpy.ufunc
have four methods. However, these methods only make
sense on scalar ufuncs that take two input arguments and return one output argument.
Attempting to call these methods on other ufuncs will cause a ValueError.
Reduces one of the dimension of the input array, by applying ufunc along one axis. 

Accumulates the result of applying the operator to all elements. 

Performs a (local) reduce with specified slices over a single axis. 

Applies the ufunc op to all pairs (a, b) with a in A and b in B. 
The current version of NLCPy does not provide nlcpy.ufunc.at()
, which is supported
by NumPy.
Optional Keyword Arguments
All ufuncs take optional keyword arguments. Most of these represent advanced usage and will not typically be used.
out
A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshlyallocated array is returned. A tuple (possible only as a keyword argument) must have length equal to the number of outputs.
where
This condition is broadcast over the input. At locations where the condition is True, the out array will be set to the ufunc result. Elsewhere, the out array will retain its original value. Note that if an uninitialized out array is created via the default
out=None
, locations within it where the condition is False will remain uninitialized.
casting
Controls what kind of data casting may occur.
'no' means the data types should not be cast at all.
'equiv' means only byteorder changes are allowed.
'safe' means only casts which can preserve values are allowed.
'same_kind' means only safe casts or casts within a kind, like float64 to float32, are allowed.
NLCPy does NOT support 'unsafe', which is supported in NumPy.
order
Specifies the calculation iteration order/memory layout of the output array. Defaults to 'K'. 'C' means the output should be Ccontiguous, 'F' means Fcontiguous, 'A' means Fcontiguous if the inputs are Fcontiguous and not also not Ccontiguous, Ccontiguous otherwise, and 'K' means to match the element ordering of the inputs as closely as possible.
dtype
Overrides the dtype of the calculation and output arrays.
subok
Not implemented in NLCPy.