4.8. utils.py¶
General utility/convenience functions
-
utils.
circularize_next_index
(i, i_max)¶ Make an index cyclic.
- Parameters
i (int) – Integer index to be converted to a cyclic index
i_max (int) – The maximum valid value of i.
- Returns
i – If input i is equal to i_max + 1, return 0, otherwise return the input i.
- Return type
int
Note
In python, list[-1] will automatically give you the last element of a list, so checking for i == -1 is redundant.
-
utils.
closed_segment_intersect
(a, b, c, d)¶ Verifies if closed segments a, b, c, d do intersect.
-
utils.
covariance
(data_1, data_2)¶ Two-pass numerically stable covariance calculation
-
utils.
cyclic_sort
(list_)¶ Find the lowest member of list and perform cyclic permuting so that the lowest member is first.
Assumes unique members.
-
utils.
gen_de_framed_mat
(temp_mat, r)¶ Return input matrix de-framed by width r.
- Parameters
temp_mat (np.array) – Matrix to be de-padded.
r (int) – Width of frame
- Returns De-framed matrix
- Rtype np.array
-
utils.
gen_fft
(mat)¶ Generate the fast Fourier transform of a matrix.
-
utils.
gen_framed_mat
(mat, r)¶ Return input matrix padded with a frame of zeros and width r.
- Parameters
mat (np.array) – Matrix to be padded.
r (int) – Width of frame
- Returns Framed matrix
- Rtype np.array
-
utils.
is_circularly_identical
(list_1, list_2)¶ Returns a boolean indicating whether list_1 and list_2 are the same in any cyclic perturbation of each other.
-
utils.
is_point_in_closed_segment
(a, b, c)¶ Returns True if c is inside closed segment, False otherwise. a, b, c are expected to be collinear
-
utils.
make_int_from_list
(list_)¶ Concatenate the menbers of a list of integers into a integer.
-
utils.
mean_val
(data)¶ Return the mean of the given data
- Parameters
data ([float] or np.array) – list or 1-d np.array with data values
- Returns mean
- Rtype float
-
utils.
multivariate_normal_dist
(x, means, covar_determinant, inverse_covar_matrix)¶ All arguments assumed to be python lists
-
utils.
normalize_static
(mat)¶ Normalize matrix such that its elements are in [0, 1]
-
utils.
side
(a, b, c)¶ Returns a position of the point c relative to the line going through a and b Points a, b are expected to be different
-
utils.
variance
(data)¶ Return the var of the given data
- Parameters
data ([float] or np.array) – list or 1-d np.array with data values
- Returns mean
- Rtype float