Most larry methods have an equivalent Numpy array function. For example, to find the zscore along the last axis of a larry, lar, you would do:
>>> lar.zscore(axis=1)
Here’s the corresponding operation on a Numpy array, arr:
>>> la.farray.zscore(arr, axis=1)
This section of the manual is a reference guide to most of the Numpy array functions available in the la package.
Functions and examples
This section contains Numpy array functions that calculate moving window summary statistics.
Note
The Bottleneck package contains fast moving window functions.
Moving window median along the specified axis.
Parameters :  arr : ndarray
window : int
axis : int, optional
method : str, optional



Returns :  y : ndarray

Examples
>>> arr = np.array([1, 2, 3, 4, 5])
>>> la.farray.move_median(arr, window=2)
array([ NaN, 1.5, 2.5, 3.5, 4.5])
Moving window median along the specified axis, ignoring NaNs.
Parameters :  arr : ndarray
window : int
axis : int, optional
method : str, optional



Returns :  y : ndarray

Examples
>>> arr = np.array([1, 2, np.nan, 4, 5])
>>> la.farray.move_nanmedian(arr, window=2)
array([ NaN, 1.5, 2. , 4. , 4.5])
Moving window ranking along the specified axis, ignoring NaNs.
The output is normalized to be between 1 and 1. For example, with a window width of 3 (and with no ties), the possible output values are 1, 0, 1.
Ties are broken by averaging the rankings. See the examples below.
Parameters :  arr : ndarray
window : int
axis : int, optional
method : str, optional



Returns :  y : ndarray

Examples
With window=3 and no ties, there are 3 possible output values, i.e. [1., 0., 1.]:
>>> arr = np.array([1, 2, 6, 4, 5, 3])
>>> la.farray.move_nanranking(arr, window=3)
array([ NaN, NaN, 1., 0., 0., 1.])
Ties are broken by averaging the rankings of the tied elements:
>>> arr = np.array([1, 2, 1, 1, 1, 2])
>>> la.farray.move_nanranking(arr, window=3)
array([ NaN, NaN, 0.5, 0.5, 0. , 1. ])
In a monotonically increasing sequence, the moving window ranking is always equal to 1:
>>> arr = np.array([1, 2, 3, 4, 5])
>>> la.farray.move_nanranking(arr, window=3)
array([ NaN, NaN, 1., 1., 1.])
Normalization functions that take a Numpy array as input.
Normalized ranking treating NaN as missing and averaging ties.
Parameters :  x : ndarray
axis : {int, None} optional
norm: str, optional :



Returns :  idx : ndarray

Notes
If there is only one nonNaN value along the given axis, then that value is set to the midpoint of the specified normalization method. For example, if the input is array([1.0, nan]), then 1.0 is set to zero for the ‘1,1’ and ‘gaussian’ normalizations and is set to 0.5 (mean of 0 and 1) for the ‘0,N1’ normalization.
For ‘0,N1’ normalization, note that N is x.shape[axis] even in there are NaNs. That ensures that when ranking along the columns of a 2d array, for example, the output will have the same min and max along all columns.
Convert elements in each column to integers between 1 and q then normalize.
Result is normalized to 1, 1.
Parameters :  x : ndarray
q : int
axis : {int, None}, optional


Returns :  y : ndarray

Examples
>>> arr = np.array([1, 2, 3, 4, 5, 6])
>>> la.farray.quantile(arr, 3)
array([1., 1., 0., 0., 1., 1.])
Subtract the mean along the specified axis.
Parameters :  arr : ndarray
axis : {int, None}, optional


Returns :  y : ndarray

Examples
>>> arr = np.array([1, np.nan, 2, 3])
>>> demean(arr)
array([ 1., NaN, 0., 1.])
Subtract the median along the specified axis.
Parameters :  arr : ndarray
axis : {int, None}, optional


Returns :  y : ndarray

Examples
>>> arr = np.array([1, np.nan, 2, 10])
>>> demedian(arr)
array([ 1., NaN, 0., 8.])
Zscore along the specified axis.
Parameters :  arr : ndarray
axis : {int, None}, optional


Returns :  y : ndarray

Examples
>>> arr = np.array([1, np.nan, 2, 3])
>>> zscore(arr)
array([1.22474487, NaN, 0. , 1.22474487])
Miscellaneous Numpy array functions.
Correlation between two Numpy arrays along the specified axis.
This is not a cross correlation function. If the two input arrays have shape (n, m), for example, then the output will have shape (m,) if axis is 0 and shape (n,) if axis is 1.
Parameters :  arr1 : Numpy ndarray
arr2 : Numpy ndarray
axis : {int, None}, optional


Returns :  corr : Numpy ndarray, scalar

Examples
Make two Numpy arrays:
>>> a1 = np.array([[1, 2], [3, 4]])
>>> a2 = np.array([[2, 1], [4, 3]])
>>> a1
array([[1, 2],
[3, 4]])
>>> a2
array([[2, 1],
[4, 3]])
Find the correlation between the two arrays along various axes:
>>> correlation(a1, a2)
0.59999999999999998
>>> correlation(a1, a2, axis=0)
array([ 1., 1.])
>>> correlation(a1, a2, axis=1)
array([1., 1.])
Shuffle the data inplace along the specified axis.
Unlike numpy’s shuffle, this shuffle takes an axis argument. The ordering of the labels is not changed, only the data is shuffled.
Parameters :  x : ndarray
axis : int


Returns :  out : None

Return the geometric mean of matrix x along axis, ignore NaNs.
Raise an exception if any element of x is zero or less.
Covariance matrix adjusted for missing returns.
covMissing returns the covariance matrix adjusted for missing returns. R (NxT) is log stock returns; missing returns are NaN.
Note the mean of each row of R is assumed to be zero. So returns are not demeaned and the covariance is normalized by T not T1.