Utilities in cr.sparse module

Array data type utilities

promote_arg_dtypes(*args)

Promotes args to a common inexact type.

check_shapes_are_equal(array1, array2)

Raise an error if the shapes of the two arrays do not match.

Utilities for vectors

is_scalar(x)

Returns if x is a scalar

is_vec(x)

Returns if x is a line vector or row vector or column vector

is_line_vec(x)

Returns if x is a line vector

is_row_vec(x)

Returns if x is a row vector

is_col_vec(x)

Returns if x is a column vector

to_row_vec(x)

Converts a line vector to a row vector

to_col_vec(x)

Converts a line vector to a column vector

vec_unit(n, i)

Returns a unit vector in i-th dimension for the standard coordinate system

vec_shift_right(x)

Right shift the contents of the vector

vec_rotate_right(x)

Circular right shift the contents of the vector

vec_shift_left(x)

Left shift the contents of the vector

vec_rotate_left(x)

Circular left shift the contents of the vector

vec_shift_right_n(x, n)

Right shift the contents of the vector by n places

vec_rotate_right_n(x, n)

Circular right shift the contents of the vector by n places

vec_shift_left_n(x, n)

Left shift the contents of the vector by n places

vec_rotate_left_n(x, n)

Circular left shift the contents of the vector by n places

vec_repeat_at_end(x, p)

Extends a vector by repeating it at the end (periodic extension)

vec_repeat_at_start(x, p)

Extends a vector by repeating it at the start (periodic extension)

vec_centered(x, length)

Returns the central part of a vector of a specified length

vec_unit_jit(n, i)

Returns a unit vector in i-th dimension for the standard coordinate system

vec_repeat_at_end_jit(x, p)

Extends a vector by repeating it at the end (periodic extension)

vec_repeat_at_start_jit(x, p)

Extends a vector by repeating it at the start (periodic extension)

vec_centered_jit(x, length)

Returns the central part of a vector of a specified length

Metrics for measuring signal and error levels

These functions are available under cr.sparse.metrics.

mean_squared(array)

Returns the mean squared value of an array

mean_squared_error(array1, array2)

Returns the mean square error between two arrays

root_mean_squared(array)

Returns the root mean squared value of an array

root_mse(array1, array2)

Returns the root mean square error between two arrays

normalized_root_mse(reference_arr, test_arr)

Returns the normalized root mean square error between two arrays

peak_signal_noise_ratio(reference_arr, test_arr)

Returns the Peak Signal to Noie Ratio between two arrays

signal_noise_ratio(reference_arr, test_arr)

Returns the signal to noise ratio between a reference array and a test array

Some checks and utilities for matrices (2D arrays)

transpose(A)

Returns the transpose of an array

hermitian(a)

Returns the conjugate transpose of an array

is_matrix(A)

Checks if an array is a matrix

is_square(A)

Checks if an array is a square matrix

is_symmetric(A)

Checks if an array is a symmetric matrix

is_hermitian(A)

Checks if an array is a Hermitian matrix

is_positive_definite(A)

Checks if an array is a symmetric positive definite matrix

has_orthogonal_columns(A[, atol])

Checks if a matrix has orthogonal columns

has_orthogonal_rows(A[, atol])

Checks if a matrix has orthogonal rows

has_unitary_columns(A)

Checks if a matrix has unitary columns

has_unitary_rows(A)

Checks if a matrix has unitary rows

off_diagonal_elements(A)

Returns the off diagonal elements of a matrix A

off_diagonal_min(A)

Returns the minimum of the off diagonal elements

off_diagonal_max(A)

Returns the maximum of the off diagonal elements

off_diagonal_mean(A)

Returns the maximum of the off diagonal elements

Row wise and column wise norms for signal/representation matrices

norms_l1_cw(X)

Computes the l_1 norm of each column of a matrix

norms_l1_rw(X)

Computes the l_1 norm of each row of a matrix

norms_l2_cw(X)

Computes the l_2 norm of each column of a matrix

norms_l2_rw(X)

Computes the l_2 norm of each row of a matrix

norms_linf_cw(X)

Computes the l_inf norm of each column of a matrix

norms_linf_rw(X)

Computes the l_inf norm of each row of a matrix

sqr_norms_l2_cw(X)

Computes the squared l_2 norm of each column of a matrix

sqr_norms_l2_rw(X)

Computes the l_2 norm of each row of a matrix

normalize_l1_cw(X)

Normalize each column of X per l_1-norm

normalize_l1_rw(X)

Normalize each row of X per l_1-norm

normalize_l2_cw(X)

Normalize each column of X per l_2-norm

normalize_l2_rw(X)

Normalize each row of X per l_2-norm

Pairwise Distances

pairwise_sqr_l2_distances_rw(A, B)

Computes the pairwise squared distances between points in A and points in B where each point is a row vector

pairwise_sqr_l2_distances_cw(A, B)

Computes the pairwise squared distances between points in A and points in B where each point is a column vector

pairwise_l2_distances_rw(A, B)

Computes the pairwise distances between points in A and points in B where each point is a row vector

pairwise_l2_distances_cw(A, B)

Computes the pairwise distances between points in A and points in B where each point is a column vector

pdist_sqr_l2_rw(A)

Computes the pairwise squared distances between points in A where each point is a row vector

pdist_sqr_l2_cw(A)

Computes the pairwise squared distances between points in A where each point is a column vector

pdist_l2_rw(A)

Computes the pairwise distances between points in A where ach point is a row vector

pdist_l2_cw(A)

Computes the pairwise distances between points in A where each point is a column vector

pairwise_l1_distances_rw(A, B)

Computes the pairwise city-block distances between points in A and points in B where each point is a row vector

pairwise_l1_distances_cw(A, B)

Computes the pairwise city-block distances between points in A and points in B where each point is a column vector

pdist_l1_rw(A)

Computes the pairwise city-block distances between points in A where each point is a row vector

pdist_l1_cw(A)

Computes the pairwise city-block distances between points in A where each point is a column vector

pairwise_linf_distances_rw(A, B)

Computes the pairwise Chebyshev distances between points in A and points in B where each point is a row vector

pairwise_linf_distances_cw(A, B)

Computes the pairwise Chebyshev distances between points in A and points in B where each point is a column vector

pdist_linf_rw(A)

Computes the pairwise Chebyshev distances between points in A where each point is a row vector

pdist_linf_cw(A)

Computes the pairwise Chebyshev distances between points in A where each point is a column vector

Sparse representations

Following functions analyze or construct representation vectors which are known to be sparse.

nonzero_values(x)

Returns the values of non-zero entries in x

nonzero_indices(x)

Returns the indices of non-zero entries in x

randomize_rows(key, X)

Randomizes the rows in X

randomize_cols(key, X)

Randomizes the columns in X

largest_indices(x, K)

Returns the indices of K largest entries in x by magnitude

hard_threshold(x, K)

Returns the indices and corresponding values of largest K non-zero entries in a vector x

hard_threshold_sorted(x, K)

Returns the sorted indices and corresponding values of largest K non-zero entries in a vector x

sparse_approximation(x, K)

Keeps only largest K non-zero entries by magnitude in a vector x

build_signal_from_indices_and_values(length, …)

Builds a sparse signal from its non-zero entries (specified by their indices and values)

dynamic_range(x)

Returns the ratio of largest and smallest values (by magnitude) in x (dB)

nonzero_dynamic_range(x)

Returns the ratio of largest and smallest non-zero values (by magnitude) in x (dB)

Sparse representation matrices (row-wise)

largest_indices_rw(X, K)

Returns the indices of K largest entries by magnitude in each row of X

take_along_rows(X, indices)

Picks K entries from each row of X specified by indices matrix

sparse_approximation_rw(X, K)

Keeps only largest K non-zero entries by magnitude in each row of X

Sparse representation matrices (column-wise)

largest_indices_cw(X, K)

Returns the indices of K largest entries by magnitude in each column of X

take_along_cols(X, indices)

Picks K entries from each column of X specified by indices matrix

sparse_approximation_cw(X, K)

Keeps only largest K non-zero entries by magnitude in each column of X

Utilities for ND-Arrays

arr_largest_index(x)

Returns the unraveled index of the largest entry (by magnitude) in an n-d array