riptable.rt_misc

Functions

autocomplete([hook, jedi, greedy])

Call rt.autocomplete() to specialize jupyter lab autcomplete output.

build_header_tuples(headers, span, group)

jedi_completions(text, offset)

autocomplete() must be called first.

output_cache_flush()

used in ipython, jupyter, or spyder

output_cache_none()

used in ipython, jupyter, or spyder

output_cache_setsize([cache_size])

used in ipython, jupyter, or spyder

parse_header_tuples(header_tups)

profile_func(func[, sortby])

Used to profile a function that has no arguments

sub2ind(aSize, aPosition)

MATLAB

riptable.rt_misc.autocomplete(hook=True, jedi=None, greedy=None)

Call rt.autocomplete() to specialize jupyter lab autcomplete output. arrays, categoricals, datetime, struct, and datasets will be detected. array will be array followed by the dtype.

Parameters:
  • hook (bool, default True) – set to False to unhook riptable autocomplete

  • jedi (bool, default None) – set to True to set use_jedi in IPython

  • greedy (bool, default None) – set to True to set greedy in IPython for [’ autocomplete

Examples

>>> rt.autocomplete(); ds=Dataset({'test':arange(5), 'another':arange(5.0), 'mycat':rt.Cat(arange(5)), 'mystr': arange(5).astype('S')})
Now in jupyter lab type 'ds.<tab>'
riptable.rt_misc.build_header_tuples(headers, span, group)
riptable.rt_misc.jedi_completions(text, offset)

autocomplete() must be called first. Not used yet. Returns the same completions jedi would.

Examples

from riptable.rt_misc import jedi_completions st = Struct({‘a’: 5}) jedi_completions(‘st’, 2)

riptable.rt_misc.output_cache_flush()

used in ipython, jupyter, or spyder calling output_cache_flush() will remove object reference in the output cache it is recommended this is called when there are memory concerns

riptable.rt_misc.output_cache_none()

used in ipython, jupyter, or spyder sets the terminalInteractiveShell output cache size to none Out[#] will no longer work the Out dictionary will be empty _# will no longer work

riptable.rt_misc.output_cache_setsize(cache_size=100)

used in ipython, jupyter, or spyder sets the terminalInteractiveShell output cache size to cache_size (100 is the default)

riptable.rt_misc.parse_header_tuples(header_tups)
riptable.rt_misc.profile_func(func, sortby='time')

Used to profile a function that has no arguments

Examples

This will time how long the __repr__ function to print out a dataset

>>> import riptable_docdata as rtd
>>> trips = rt.Dataset(rtd.get_bike_trips_data('trips'))
>>> profile_func(trips.__repr__)
riptable.rt_misc.sub2ind(aSize, aPosition)

MATLAB

sub2ind Linear index from multiple subscripts. sub2ind is used to determine the equivalent single index corresponding to a given set of subscript values.

IND = sub2ind(SIZ,I,J) returns the linear index equivalent to the row and column subscripts in the arrays I and J for a matrix of size SIZ.

IND = sub2ind(SIZ,I1,I2,…,IN) returns the linear index equivalent to the N subscripts in the arrays I1,I2,…,IN for an array of size SIZ.

I1,I2,…,IN must have the same size, and IND will have the same size as I1,I2,…,IN. For an array A, if IND = sub2ind(SIZE(A),I1,…,IN)), then A(IND(k))=A(I1(k),…,IN(k)) for all k.

PYTHON

ravel_multi_index(…) ravel_multi_index(multi_index, dims, mode=’raise’, order=’C’)

Converts a tuple of index arrays into an array of flat indices, applying boundary modes to the multi-index.

Parameters:
  • multi_index (tuple of array_like) – A tuple of integer arrays, one array for each dimension.

  • dims (tuple of ints) – The shape of array into which the indices from multi_index apply.

  • mode ({'raise', 'wrap', 'clip'}, optional) –

    Specifies how out-of-bounds indices are handled. Can specify either one mode or a tuple of modes, one mode per index.

    • ’raise’ – raise an error (default)

    • ’wrap’ – wrap around

    • ’clip’ – clip to the range

    In ‘clip’ mode, a negative index which would normally wrap will clip to 0 instead.

  • order ({'C', 'F'}, optional) – Determines whether the multi-index should be viewed as indexing in row-major (C-style) or column-major (Fortran-style) order.

Returns:

raveled_indices – An array of indices into the flattened version of an array of dimensions dims.

Return type:

ndarray

See also

unravel_index

Notes

New in version 1.6.0.

Examples

>>> arr = np.array([[3,6,6],[4,5,1]])
>>> np.ravel_multi_index(arr, (7,6))
array([22, 41, 37])
>>> np.ravel_multi_index(arr, (7,6), order='F')
array([31, 41, 13])
>>> np.ravel_multi_index(arr, (4,6), mode='clip')
array([22, 23, 19])
>>> np.ravel_multi_index(arr, (4,4), mode=('clip','wrap'))
array([12, 13, 13])
>>> np.ravel_multi_index((3,1,4,1), (6,7,8,9))
1621