numpy_helper_functions

Auxiliary functions for numpy.ndarrays and general mathematical functions.

This module can be called from mdtools via the shortcut nph:

import mdtools as mdt
mdt.nph  # instead of mdt.numpy_helper_functions

Todo

Finish/revise the implementation of the functions and their docstrings. Revision is finished until mdtools.numpy_helper_functions.ceil_divide() (in source code order, not the alphabetical documentation order). Basically, this means that all functions having an ‘Examples’ section in their docstring are revised, all other functions are not.

Functions

argmax_last

Get the indices of the maximum values along an axis.

argmin_last

Get the indices of the minimum values along an axis.

ceil_divide

Calculate element-wise ceil division.

cross_section

Extract a cross section from a 2-dimensional array along a given line using scipy.ndimage.map_coordinates().

cross_section2d

Extract a cross section from a 2-dimensional array along a given axis.

diff_mic

Calculate the difference between array elements respecting the minimum image convention.

digitize_dd

Return the indices of the multi-dimensional bins to which each value in the input array belongs.

excel_colname

Convert an integer to its corresponding Excel-style column name.

excel_colnum

Convert an Excel-style column name to its corresponding integer number.

extend

Extend an axis of an array to a given length by padding a given value at the end of the axis.

find_const_seq_long

Find the longest sequence of constant values in an array.

find_const_seq_n

Find the first sequence of at least n constant values in an array.

find_linear_region

Find linear regions in a data array.

find_nearest

Find the values in an array which are closest to a given value along an axis.

get_const_seqs

Get all sequences of constant values in an array.

get_middle

Get the n innermost elements of a 1-dimensional array.

group_by

Group the elements of values by their keys.

item_change_ix

Get the indices of item changes in an array.

ix_along_axis_to_global_ix

Construct a tuple of index arrays suitable to directly index an array a from an array of indices along an axis of a.

ix_of_item_change

Get the indices of an array where its elements change along a given axis.

ix_of_item_change_1d

Get the indices of a 1-dimensional array where its elements change.

locate_item_change

Locate the positions of item changes in an array.

match_shape

Bring two arrays to the same shape by padding a given value at the end of of the axes of the shorter array.

sequenize

"Sequenize" the values of an array.

split_into_contig_seqs

Split an array into subarrays of contiguous sequences.

subtract_mic

Subtract two arrays element-wise respecting the minium image convention.

symmetrize

Create a symmetrized copy of a 2-dimensional array.

take

Take a slice from an array along an axis.

tilt_diagonals

Tilt a 2-dimensional array by 45 degrees so that the diagonals will either be converted to columns (if tilted clockwise) or to rows (if tilted counterclockwise).

trailing_digits

Get the number of trailing digits in an integer.

trapz2d

Integrate z(x,y) within the given limits using numpy.trapz twice, first in y and then in x direction.